Issue
I am writing an android application where I make a request through volley and load that into the web view. But now when I connect to a public wifi (say Starbucks or some hotel) where the user first needs to signin, when i make a request the login page is returned where the user puts his credentials (email, password or whatever) and that is loaded into the web view. But i need to detect that the wifi first needs to signin and show user a message to login through browser
Solution
In such a case, the Captive portal is redirecting you to the login page. Base on the valley configuraions, it may or may not get an error. (See this). So you can disable volley redirection, and in onErrorResponse(VolleyError error)
callBack method, check if you getting error code 302, then you have to open the browser for user or whatever you want to do to handle this case.
To check for response code do this:
@Override
public void onErrorResponse(VolleyError error) {
NetworkResponse networkResponse = error.networkResponse;
if (networkResponse != null && networkResponse.statusCode == 302) {
// Open the browser
}
}
EDIT:
If you get any error, you can simple check the error and decide whether open a browser for user or not.
But if you getting the result in onRespose
and not getting a 302 as an error, you should check for response code and use the following code instead to be able to check the response code:
queue.add(new Request<String>(Method.GET, url, errorListener) {
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
if (response != null && reponse.statusCod == 302){
// Open the browser for user, or whatever you want to do
}
return null;
}
@Override
protected void deliverResponse(String response) {
}});
Also Check here too
Answered By - Sadegh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.