Android webview 调起微信支付

啥都不说,直接上代码

mWebView.setWebViewClient(new MyWebViewClient());
private class MyWebViewClient extends WebViewClient 
{
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) 
    {
        try 
        {
            if (url.startsWith("weixin://wap/pay?")) 
            {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(url));
                startActivity(intent);
            }
        }
        catch (Exception e) 
        {
            e.printStackTrace();
            //调起微信页面失败,自己看着办...
        }
        super.onPageStarted(view, url, favicon);
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request)
    {
        //高版本可以在这里拦截,but低版本这里不会每次都调用!
        //根据测试Android 6.0在这拦截无效
        return super.shouldOverrideUrlLoading(view, request);
    }
}

 

你可能感兴趣的:(Android)