Denied starting an intent without a user gesture

来源:互联网 发布:sqlserver 索引维护 编辑:程序博客网 时间:2024/06/10 08:14

前端 写了个 网页替换replace 方法。发现在Android 7.0系统不执行,而Android 5.1 系统上却可以正常运行。webview并没有做复杂的功能只是有俩个js交互的方法。

看到log日志中 一直在输出:  W/cr_AwContentsClient: Denied starting an intent without a user gesture, URI http://网址.html。


意图被拒绝。

先说解决办法:webview添加这句话即可。

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

是什么导致这个问题的呢:

  1. From newest androids, the WebView and Chrome Client is separated application which can be automatically updated without user intention.

  2. From Chrome x >= 25 version, they changed how loading url is working in android application which is using webview component. https://developer.chrome.com/multidevice/android/intentsLooks like they are blocking changing url without user gesture and launched from JavaScript timers

Solution here is to force user to activate URL change, for example on button click.

Also, you can override method mentioned above "shouldOverrideUrlLoading" in WebView client.

大概意思就是 Chrome 版本>=25的时候,意图对象就被拒绝了。解决办法就是:强制启动一个URL 或者在 安卓客户端重写shouldOverrideUrlLoading 这个方法。

  假如安卓端不方便更新应用了,有没有办法解决呢?答案是肯定的, 我们点进去上面的网址(需要科学上网),发现官方给出的办法:

1、The best practice is to construct an intent anchor and embed that into the page so the user can launch the app. This gives you a lot more flexibility in controlling how apps are launched, including the ability to pass extra information into the app via Intent Extras.

2、Also, you may choose to specify fallback URL by adding the following string extra:
S.browser_fallback_url=[encoded_full_url]
When an intent could not be resolved, or an external application could not be launched, then the user will be redirected to the fallback URL if it was given.


一起学习Android的朋友,请联系我springlovvol@163.com 






阅读全文
0 0