在WebChromeClient中拦截来自WebView的请求

时间:2017-07-19 10:48:23

标签: android webchromeclient

我有一个与此相关的问题:Prevent data from loading using shouldInterceptRequest

我知道我现在需要使用WebChromeClient,但我不知道这个类中的哪个方法等同于shouldInterceptRequest。这是另一个特殊的类或任何WebChromeClient方法是为此而制定的吗?我试过onPermissionRequest(),但我觉得它不是为此做的。

这就是我想要实现的,在外部浏览器应用程序中打开一个链接:

Uri webpage = Uri.parse(request.getUrl().toString());
Intent webIntent = new Intent(Intent.ACTION_VIEW, webpage);
webIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PackageManager packageManager = view.getContext().getPackageManager();
List activities = packageManager.queryIntentActivities( webIntent, PackageManager.MATCH_ALL);
boolean isIntentSafe = activities.size() > 0;
if(isIntentSafe) view.getContext().startActivity(webIntent);

我想我只需要将此代码放入正确的方法中。

0 个答案:

没有答案