Reputation: 807
Is there a way if I can check status code for the url I load into a webview? I want to check if the url has anymore redirects, and if not I want to execute a piece of code.
Iam implementing the WebViewClient and I want to execute a code in the onPageFinished();
EDIT: The url I load is a login screen. I want to check if the user has successfully logged in.
How can I achieve this?
Upvotes: 4
Views: 2732
Reputation: 9
Try this
public void evaluateJavascript (String script, ValueCallback<String> resultCallback)
Upvotes: -1
Reputation: 2198
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.isEmpty()){
// do your stuff as you want.
}
return true;
}
public void onPageFinished(WebView view, String url) {
// do your stuff as you want
}
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
}
});
Upvotes: 2
Reputation: 2381
Use HttpURLConnection class.
URL url = new URL("http://example.com");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
int code = connection.getResponseCode();
There you have the http code returned.
Hope this helps.
Upvotes: 1