preface
An error occurred when calling webViewH5 in Android, as shown in the figure below:
Error graph
Solution:
Add the following code, otherwise the operating system will block the URL of the payment and you cannot open the Alipay page, so we need to manually determine the URL address
/ / this method support pay treasure and pay WeChat mWebView setWebViewClient (new WebViewClient () {@ Override public Boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.startsWith("http:") || url.startsWith("https:")) { return false; } try { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(intent); } catch (Exception e) { Log.e(TAG, " Exception is ==== >>> " + e); } return true; }});Copy the code
I’m going to put a try catch here, because the URL that you’re passing is not necessarily a valid URL. It may be the url to open your local app, which will crash if you don’t have it installed
Wechat calls another method
mWebView.setWebViewClient(new 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(); Toastutils. showShort(webViewActivity. this," Call wechat payment failed!" ); } super.onPageStarted(view, url, favicon); mProgressBar.setVisibility(View.VISIBLE); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); mProgressBar.setVisibility(View.GONE); } @Override public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { super.onReceivedError(view, request, error); Toastutils.showshort (webViewActivity. this, "failed to load "); }});Copy the code
The webView.gif image was successfully invoked
‘
I want to work my way up
Fly forward on the blades at the highest point
Let the wind blow dry tears and sweat
I want to work my way up
Waiting for the sun to watch its face
Little days have big dreams
I have my day
Let the wind blow dry tears and sweat
One day I will have my day