In my application there is a Login screen at the very first time which shows in a web view. In that screen a pop up will appear which has UserName and Password. After giving the details when the Log in button is pressed the UserName and password is submitted and a it will call a php code for username and password validation which redirects to a link which will reload in the webview. When this URL is loaded I have to listen the URL and if the URL matches some consideration i want to finish the webview activity and move on to next activity.
The problem is as when I cant Listen the URL that generates after the login. As the Login button does not have a login, shouldOverrideUrlLoading is not calling. I tried using onPageFinished, onLoadResource, onPageStarted. But only few devices calling these function.
I want to get the URL after the Login button is pressed. Is there any other way to solve this problem.
This is my code:
public class AndroidTestActivity extends Activity {
/** Called when the activity is first created. */
WebView mWebView;
Context ctx;
String str = "";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ctx = this;
mWebView = (WebView) findViewById(R.id.mywebview);
mWebView.setWebViewClient(new MyWebClient());
mWebView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);
WebSettings webSettings = mWebView.getSettings();
webSettings.setSavePassword(false);
webSettings.setSaveFormData(false);
webSettings.setJavaScriptEnabled(true);
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView view, String url, String message,
android.webkit.JsResult result) {
// Required functionality here
return super.onJsAlert(view, url, message, result);
}
});
mWebView.loadUrl("http://This is my log in screen");
}
class MyWebClient extends WebViewClient {
MyWebClient() {
Log.e("test", "Inside WebViewClient");
}
public void onPageStarted(WebView view, String url, Bitmap favicon) {
Log.e("onPageStarted", url);
str = str + "onPageStarted : " + url + "\n";
}
public void onLoadResource(WebView view, String url) {
Log.e("onLoadResource", url);
str = str + "onLoadResource : " + url + "\n";
}
public void onPageFinished(WebView view, String url) {
Log.e("onPageFinished", url);
str = str + "onPageFinished : " + url + "\n";
}
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.e("shouldOverrideUrlLoading", url);
str = str + "shouldOverrideUrlLoading : " + url + "\n";
return true;
}
}
}
Thanks Regards, Sniper.