Webview : Denied starting an intent without a user gesture

起始

在 H5 的页面中我调用了如下的 JS 代码

<script>
function reLocation(){
window.location.href = "./welcome_daily.html";
}
setTimeout("reLocation()", 2000);
</script>

这在 4.4 的手机上正常运行,在一台 7.0 ,一台 8.0 的机器上却没有任何反应,并且也没有崩溃。

排错

在排除了 H5 错误的可能性之后,那么就只可能是 webView 不同版本的兼容问题了,然后我在 AS 的 log 窗口中,看到了一条 描述性的语句: Denied starting an intent without a user gesture … file:///android_asset/html/welcome_daily.html。
从上面的摘出来的日志中,我可以确定的是 JS 代码是被执行了,那么就是 webView 不知为何拦截了这次 H5 自身的跳转。

解决

最终通过 stackoverflow/google/百度 确认了问题。
Denied starting an intent without a user gesture
在此先感谢作者,正如作者文中所言

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

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

这里写图片描述

最终

这里写图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值