Android WebView 支持微信支付
( 请先确认测试手机上安装微信 并登陆 !!! )
![](https://img.haomeiwen.com/i7034790/da9515409bb2c971.jpg)
直接上代码 :
webView.setWebViewClient(new WebViewClient() {
//覆盖shouldOverrideUrlLoading 方法
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
"http://www.gxshapp.com"
if (url == null) return false;
try {
// ===========调用支付宝===========
if (parseScheme(url)) {
Intent intent;
intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
intent.addCategory("android.intent.category.BROWSABLE");
intent.setComponent(null);
startActivity(intent);
return true;
}
// ===========调用微信===========
if (url.startsWith("weixin://")) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
return true;
}
} catch (Exception e) {
return false;
}
if (url.startsWith("http://") || url.startsWith("https://")) {
Map<String, String> map = new HashMap<>();
map.put("Referer","http://www.gxshapp.com");
wv.loadUrl(url, map);
return true;
} else {
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
} catch (Exception e) { //防止crash (如果手机上没有安装处理某个scheme开头的url的APP, 会导致crash)
return false;
}
}
}
});
Map<String, String> map = new HashMap<>();
map.put("Referer",referer);
view.loadUrl(url, map);
网友评论