问题:webview调用微信app进行支付的时候 无法唤醒微信,只能跳出选择浏览器的弹框
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
try {
Log.d("UMHybrid", "shouldOverrideUrlLoading url:" + url);
String decodedURL = java.net.URLDecoder.decode(url, "UTF-8");
if (url.startsWith("https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?") || url.startsWith("weixin://wap/pay?")) {/* WebView 唤起微信支付页面*/
try {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
mContext.startActivity(intent);
} catch (android.content.ActivityNotFoundException e) {
Toast.showSToast(mContext, "未安装微信");
Log.e(TAG, "shouldOverrideUrlLoading: e=" + e.toString());
}
return true;
}
return super.shouldOverrideUrlLoading(view, url);
} catch (Exception e) {
e.printStackTrace();
}
return super.shouldOverrideUrlLoading(view, url);
}
解决方案:
Map<String, String> extraHeaders = new HashMap<String, String>();
extraHeaders.put("Referer", "http://www.xxxxxx.com");//商户申请H5时提交的授权域名
view.loadUrl(url, extraHeaders);
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
try {
Log.d("UMHybrid", "shouldOverrideUrlLoading url:" + url);
String decodedURL = java.net.URLDecoder.decode(url, "UTF-8");
if (url.startsWith("https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?")) {
Map<String, String> extraHeaders = new HashMap<String, String>();
extraHeaders.put("Referer", "http://www.xxxxxx.com");//商户申请H5时提交的授权域名
view.loadUrl(url, extraHeaders);
return true;
} else if (url.startsWith("weixin://wap/pay?")){
try {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
cordova.getActivity().startActivity(intent);
} catch (android.content.ActivityNotFoundException e) {
DialogUtil.toast(cordova.getActivity(), "未安装微信");
Log.e(TAG, "shouldOverrideUrlLoading: e=" + e.toString());
}
}
} catch (Exception e) {
e.printStackTrace();
}
return super.shouldOverrideUrlLoading(view, url);
}