How to get page state in webview - android

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.

Related

Android WebView ERR_TOO_MANY_REDIRECTS

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.

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?

Android WebView Uncaught Reference Error

I have a simple WebView in my app that loads the Google Finance page with a specific symbol so users can see historical prices and other information, but for some reason in the Log I keep seeing this message when loading the webview:
I/chromium﹕ [INFO:CONSOLE(242)] "Uncaught ReferenceError: og is not defined", source: https://www.google.com/m/finance#search/GOOG (242)
Although this doesn't prevent the webview from loading the url, I don't understand why I'm getting that message. I've tried with numerous ticker symbols (for example replace GOOG with AXP, BUD, CMCSK) and the message is always the same so I'm thinking it's referring to the "google" part of the url but I don't know why it would come up as not defined.
It is simply a javascript error that happened on the specific page you loaded.
Try loading the page:
https://www.google.com/m/finance#search/GOOG
in browser with opened developer console and you will see something like this:
==> as long as you do not control the webpage you are loading there is not much what you can do about that. Except maybe checking if the url etc. that you use is the right one.

get method dosen't return a right result

I'm tring to build a android client for a website, of which I have no control. I can only use httpwatch to detect the data flow and decide to use either post method or get mathod.
Here I come across a problem, after logining in the website, I click a button to load some data(the url in the browser dosen't change,name it url-1), it works well and the httpwatch tells it is using get method with a target url(a different one,name it url-2). If I paste the url(url-2) in the brower it returns to the login page without loading any data. I check the html source code and find the iframe tag, which may be used to realize local refresh.
In android, I use httpclient to do post or get, I can login in and keep a connection with the server, but I failed when tring to use get method to load some new data, it also returns the login page.
Why it works like this, is there any way to get the right answer?

what the reason behind <GATE-M>DEV_ACTION_ERROR</GATE-M> android logs

My application is using web view and every thing is working fine(no force close,no visible error) but in log cat i am getting unlimited and continuous logs like.
09-06 09:05:27.464: I/GATE(3471): <GATE-M>DEV_ACTION_ERROR</GATE-M>
my web view renders a local html file which resides in asset folder.From Android native code i am sending some string to webview to call a java script function.
because of unlimited logs i am not able to see my custom log message.
Can any please tell me the reason so can eliminate if i did any thing wrong.
I am loading the WebView using the Url from server. In my case it is not html file. Just check the input stream from the server. if any content is there then set webview otherwise dont.

Categories

Resources