赞
踩
参考:https://www.jianshu.com/p/167457b65f78
一、问题:安卓app通过webview调用支付宝,显示错误信息:
alipays://platformapi/startApp ERR_UNKNOWN_URL_SCHEME
二、解决办法:
给WebView设置WebViewClient并重写WebViewClient的shouldOverrideUrlLoading()方法
完整代码如下:
- WebViewClient webViewClient = new WebViewClient() {
- @Override
- public boolean shouldOverrideUrlLoading(WebView wv, String url) {
- if(url == null) return false;
-
- try {
- if(url.startsWith("weixin://") || url.startsWith("alipays://") ||
- url.startsWith("mailto://") || url.startsWith("tel://")
- //其他自定义的scheme
- ) {
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
- startActivity(intent);
- return true;
- }
- } catch (Exception e) { //防止crash (如果手机上没有安装处理某个scheme开头的url的APP, 会导致crash)
- return false;
- }
-
- //处理http和https开头的url
- wv.loadUrl(url);
- return true;
- }
- };
- webview.setWebViewClient(webViewClient);

关于自定义Scheme可以参考官网说明: https://developer.android.com/training/basics/intents/filters.html
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。