I think it's a common way to use shouldOverrideUrlLoading
to detect URL loading in Android's WebView, but for pages like SPA (single page application) where submit doesn't run, this method detects events. I can't.
Use the WebViewClient's doUpdateVisitedHistory
.
doUpdateVisitedHistory is a database of visited links The method to update.
mWebView.setWebViewClient( new WebViewClient(){
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Log.d(TAG, "shouldOverrideUrlLoading LOLLIPOP url = " + request.getUrl().toString());
return false;
}
@SuppressWarnings("deprecation")
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.d(TAG, "shouldOverrideUrlLoading url = " + url);
return false;
}
@Override
public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) {
Log.d(TAG, "doUpdateVisitedHistory url = " + url);
}
});
Now, let's access the SPA from WebView.
06-29 10:10:50.756 13453-13453/jp.sample D/WebViewFragment: doUpdateVisitedHistory url = https://xxxx/profile/home
06-29 10:34:41.636 13453-13453/jp.sample D/WebViewFragment: doUpdateVisitedHistory url = https://xxxx/connect
06-29 10:34:41.658 13453-13453/jp.sample D/WebViewFragment: doUpdateVisitedHistory url = https://xxxx/logout
06-29 10:34:41.671 13453-13453/jp.sample D/WebViewFragment: doUpdateVisitedHistory url = https://xxxx/connect
06-29 10:34:44.131 13453-13453/jp.sample D/WebViewFragment: doUpdateVisitedHistory url = https://xxxx/signin
06-29 10:34:54.526 13453-13453/jp.sample D/WebViewFragment: doUpdateVisitedHistory url = https://xxxx/auth/callback?token=xxxx
I was able to detect it safely!
Recommended Posts