webview 只识别https和http开头的地址
webview调用setWebViewClient方法,重写shouldOverrideUrlLoading方法,返回return super.shouldOverrideUrlLoading(view, url);就可以跳转到申请权限界面了,要登录QQ去申请权限的时候报错,因为这里会返回一个带intent://的地址,只能跳转到外部。要设置
settings.setDomStorageEnabled(true);
以下是具体代码:
mwebMain.setWebViewClient(new WebViewClient() { @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { Log.d("myapp", "SslError=" + error); //等待证书响应 handler.proceed(); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Log.d("myapp", "url=" + url); // view.loadUrl(url); // return true; if (url.startsWith("intent://")) { Uri parsedUri = Uri.parse(url); PackageManager packageManager = context.getPackageManager(); Intent browseIntent = new Intent(Intent.ACTION_VIEW).setData(parsedUri); try { Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME); if (intent.resolveActivity(context.getPackageManager()) != null) { context.startActivity(intent); return true; } //try to find fallback url String fallbackUrl = intent.getStringExtra("browser_fallback_url"); if (fallbackUrl != null) { mwebMain.loadUrl(fallbackUrl); return true; } //invite to install Intent marketIntent = new Intent(Intent.ACTION_VIEW).setData( Uri.parse("market://details?id=" + intent.getPackage())); if (marketIntent.resolveActivity(packageManager) != null) { context.startActivity(marketIntent); return true; } } catch (URISyntaxException e) { //not an intent uri } return true; } return super.shouldOverrideUrlLoading(view, url); } });
webview打开微信地址跳转:文章来源:https://www.toymoban.com/news/detail-741930.html
url以weixin://开头的要再shouldOverrideUrlLoading增加以下判断方法:文章来源地址https://www.toymoban.com/news/detail-741930.html
if (url.startsWith("weixin://") || url.startsWith("alipays://") || url.startsWith("mqqapi://")) { //打开本地App进行支付 Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); startActivity(intent); return true; }
到了这里,关于android webview 打开腾讯文档不跳转到申请权限界面显示ERR_UNKNOWN_URL_SCHEME的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!