Android WebView ERR_TOO_MANY_REDIRECTS - android

I am trying to allow user to login into our application through a WebView, but when trying to login, I get an error saying ERR_TOO_MANY_REDIRECTS. The login protocol consists of 5 redirects, but we have no control over it.
It works in a web browser, but Anroid WebView starts thinking we are in a redirect loop and cancels the whole thing. Up until API 8 there was a function onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg), which allowed you to continue, but is now not used anymore.
What can I do to get around this problem?

In my code I have the following line:
webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
Just deleting this line solve the issue.

Related

Android WebView and Laravel login error

I have a Laravel application with login.
It all works fine in a browser, but if I use Android WebView, and try to login, I get an error
Trying to get property of non-object
This is because, when I try and get the user with Auth::user(); it returns null.
I am logging my user in using auth()->login($user) in a function. If I dd($user) at this step, it does get the correct user - but then I redirect into /dashboard which then fires a function, where the first thing it does is to try and get the user.
Its at this point it breaks.
This all works in a browser - also in an android browser. But not in Webview.
Can this have anything to do with the session cookie or something? Is it possible to try and dd() the session cookie to see if it exists?
And if it doesn't, how come this isn't setting in Android Webview?
I have tried using CookieManager.getInstance().setAcceptCookie(true); but this isn't helping, and should also be defined by default.
All help appreciated

Android Studio access webcam via WebView

I'm trying to access and display a webcam interface in my application.
Currently I'm trying to do that using a WebView (still no success), but open to other suggestions.
When I go to "http://192.168.43.74:81" (the ip of the camera) on my phone's browser I get a popup asking me to insert a username and a password, I do that and log the camera successfully.
This is how I try to do that using a WebView:
WebView camera = (WebView) findViewById(R.id.camera);
camera.getSettings().setJavaScriptEnabled(true);
camera.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
camera.loadUrl(CAMERA_URL);
camera.setWebViewClient(new WebViewClient());
When I set CAMERA_URL to google's url for example, I'm able to access google and browse the internet normally, using the webview. When I set CAMERA_URL to the webcam's IP, I get a blank page on my webview, and the following message:
Access Error: Unauthorized
Access to this document requires a User ID
This is the same message I get when I try to log in via my browser, but hit cancel instead of trying to log in. I assume I'm doing something wrong, and would appreciate some help:
How do I make it work?
Is there a better way to go about it than a WebView?
and finally, though a somewhat different question, is there a way to automatically make the login instead of having the user type the username/password every time?
I apologize if this question is trivial, or has been asked before. I was unable to find a solution by searching. Thank you!

oAuth support in a WebView

So I've created a simple WebView application that wraps an already existing mobile friendly site and displays it on the device. I've enabled javascript, supported screen orientation changes, etc...
I've run into an issue with the oAuth support though. Accessing the site from the chrome browser on the device, everything runs fine.
If I try to access the site from the app/WebView, it will push me over to the oAuth screen, let me input credentials and everything, but the moment it tries to push me back to the website and log me in, I get this:
Failed to recognize URL query:
https://exittix.com/frontend/login/redirect.html#access_token=******************************&expires_in=********&state=****client_id=******************network*****facebook*****display***popup****callback****_hellojs_agj27sx5****state****oauth_proxy***https***auth-server.herokuapp.com%2Fproxy***scope***basic_profile***email***basic***oauth***version***auth***https***facebook.com%2Foauth***
The * is used to protect data.
So, any ideas why oAuth isn't working inside a JS enabled webview but works fine in the mobile chrome browser for android?
Thanks in advance for your help!
EDIT:
Ok, so I've tracked the error I'm getting back to redirect.html.
This page calls some javascript. If the javascript fails to redirect, then it displays that error I have above instead.
The javascript being called to handle the oAuth is Andrew Dodson's hello.js script.
You can see it HERE.
I've concluded that the second half of the error's url is indeed the unhandled JSON.
Here's what the returned data looks like after I've decoded it from the URL encoded characters:
{"client_id":"************.apps.googleusercontent.com","network":"google","display":"popup","callback":"_hellojs_********","state":"","oauth_proxy":"https://auth-server.herokuapp.com/proxy","scope":["https://www.googleapis.com/auth/userinfo.profile","https://www.googleapis.com/auth/userinfo.email","basic"],"oauth":{"version":2,"auth":"https://accounts.google.com/o/oauth2/auth"}}&access_token=***.*.*****_*********************************************************&token_type=Bearer&expires_in=3600
Any ideas why this isn't getting handled properly in the WebView?

How to get page state in webview

In my Android app, I have need to show a webpage in a WebView, using the URL obtained from my server. However, it sometimes shows OK but sometimes shows an error page (a .NET-style yellow page stating "Server Error in /Web Application").
I want to do something in my app to identify that error and redirect to another page, but how do I recognize the error?
See How to retrieve HTML content from WebView (as a string)
Check the HttpResponse code and see if there's error returned.
Take note of the comment to avoid consuming double of the bandwidth required, make a HttpRequest and load it into the WebView if there's not error.

Android webview.loadUrl works with one URL GET string but not Another

I am new at Java and Android so thank for you help.
I wrote a simple Android WebView app to view my home webcam. I can get webview to return a snapshot of the webcam but not send controls to pan etc.
The line that works is
webview.loadUrl("http://myhost.com/snapshot.cgi?user=myusername&pwd=mypassword");
This works and returns a snapshot of my current webcam a FOSCAM
This line DOES NOT WORK!
webview.loadUrl("http://myhost.com/decoder_control.cgi?command=28?user=myusername&pwd=mypassword");
The above line uses that same username / password but returns a HTTP 401 Unauthorized error
WHAT is going on.. they both work fine in a browser? and in CURL
It's likely the second question mark... Why is that there? I imagine it should be an ampersand unless you have some weird protocol.

Categories

Resources