1. 程式人生 > >終極解決方案:在webview中跳轉支付寶出錯,net::ERR_UNKNOWN_URL_SCHEME

終極解決方案:在webview中跳轉支付寶出錯,net::ERR_UNKNOWN_URL_SCHEME

如果你在webview裡面,死活都沒有掉起支付寶.跳轉過去就掛掉,

第一步,請你在模擬器跑一遍, 如果你發現你網頁返回,報錯是:net::ERR_UNKNOWN_URL_SCHEME

那麼複製這段程式碼到你的專案裡就OK

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; } };