【发布时间】:2017-12-08 01:00:48
【问题描述】:
我有第三方支付公司的 webview。我不想获取发布数据,我只想知道用户是否已经提交以锁定应用程序中的操作,因此在该过程完成之前他不能做任何事情。
根据 android 文档 WebViewCLient 不会在 shouldOverrideUrlLoading() 上使用 post 方法执行此操作。
【问题讨论】:
我有第三方支付公司的 webview。我不想获取发布数据,我只想知道用户是否已经提交以锁定应用程序中的操作,因此在该过程完成之前他不能做任何事情。
根据 android 文档 WebViewCLient 不会在 shouldOverrideUrlLoading() 上使用 post 方法执行此操作。
【问题讨论】:
我没有找到完全做到这一点的方法,但我的解决方法是在 Web 客户端上覆盖 shouldInterceptRequest(WebView view, WebResourceRequest request),然后在那里使用 request.hasGesture() 来知道该请求是由用户触发的行动
私有最终 WebViewClient webViewClient = new WebViewClient() {
@覆盖
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if(request.hasGesture()){
//屏蔽屏幕
}
}
返回 super.shouldInterceptRequest(view, request);
}
}
【讨论】: