Refused intention without gestures of user Webview Android

Trying to redirect a local html page in an Android web browser using Javascript redirection, it is denied intent in Logcat:

Testing on Android 5.1.1

document.location = "index.html";

Refused intent without user gestures, URI:

file:///android_asset/index.html

+8
android android-intent webview
source share
4 answers

I read the documentation in 1000 attempts of Android.developer and that was my solution

I don’t know if you understand, I speak Spanish.

 webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return false; } }); 
+34
source share

This worked for me:

 webView.setWebViewClient(new WebViewClient()); 
+5
source share

Here are a few issues.

  • From the new androids, WebView and the Chrome client are a separate application that can be automatically updated without the intention of the user.

  • From the version of Chrome x> = 25, they changed the way url is loaded in an Android application using the webview component. https://developer.chrome.com/multidevice/android/intents It seems that they block changing the URL without user gestures and are triggered from JavaScript timers

The solution here is to force the user to activate the URL change, for example, when a button is clicked.

Alternatively, you can override the "shouldOverrideUrlLoading" method in the WebView client above.

0
source share

As an alternative, I realized that I need to add addJavascriptInterface for each action when I click the event event button on the JavascriptInterface

 webView.addJavascriptInterface(new java2JSAgent(), "java2JSAgentVar"); //webView webview object public class java2JSAgent { @JavascriptInterface public String getContacts() { String jsonResponse = "{result:'redirected'}"; runOnUiThread(new Runnable() { @Override public void run() { webView.loadUrl("file:///android_asset/index.html"); } }); return jsonResponse; } } 

may not be a good approach, but at least its work :-) Thanks

-one
source share

All Articles