Denied starting an intent without a user gesture

前端 写了个 网页替换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.

 

 

 

 

 

 

 

 

 

 

 

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七彩麻雀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值