Open the chrome custom tab from Android web browser: CustomURL and untrusted content handler

I am trying to open a custom Chrome tab from a web view inside an Android application. To do this, I decided that I could register my own URL handler (customtab: //www.myurl.com/). The error I came across is that chrome (web browsing) blocks its own URL handler due to an insecure content error (this request was blocked, the content must be transmitted via HTTPS.). URL is https. Even adding webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);to webView did not help.

Any ideas on how I can register this custom handler as “safe”?

+4
source share
4 answers

You can use web intent to open url in chrome

Intent webIntent = new Intent (Intent.ACTION_VIEW);

webIntent.setData (Uri.parse (URL));

getActivity () startActivity (webIntent) ;.

0
source

You need to override this method in Webview to skip ssl errors

public synchronized void onReceivedSslError(WebView view, final SslErrorHandler handler,SslError error) {
        handler.proceed();                      
      }
0
source

URL- - android, .

- ,

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_margin="20dp"
    android:gravity="center"
    android:background="#ffffff">

    <WebView
        android:id="@+id/WebView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp"/>

</RelativeLayout>

.java onCreate

webView = (WebView) findViewById(R.id.WebView);
        windowwidth = getWindowManager().getDefaultDisplay().getWidth();
        windowheight = getWindowManager().getDefaultDisplay().getHeight();

        getWindow().setLayout(windowwidth, windowheight);

        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setAppCacheEnabled(false);
        settings.setDomStorageEnabled(true);





        try {
// here i call progressdialog which is load still the page is not load //properly
            Constants.ShowProgressDialog(MyActivity.this, "", "Please wait...");


            webView.setWebViewClient(new WebViewClient() {
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    Log.i("", "Processing webview url click...");
                    view.loadUrl(url);
                    return true;
                }

                public void onPageFinished(WebView view, String url) {
                    Log.i("", "Finished loading URL: " + url);
// dismiss the progressbar after load the web page in webview.
                    Constants.disMisProgressdialog();
                }


                @Override
                 public void onLoadResource(WebView view, String url) {
                    super.onLoadResource(view, url);
                }
            });

                webView.loadUrl("<your url>");

        } catch (Exception e) {
            e.printStackTrace();
        }

- , , URL-. .

, .

, .

"<" - android: name= "android.permission.INTERNET" / " > " ( quatation)

0

WebViewClient WebView shouldOverrideUrlLoading() :

public boolean shouldOverrideUrlLoading(WebView view, String url) {
  if (url.startsWith("custometab://")) {
    // TODO: start custom tabs for the url.
    return true;
  } else {
    return false;
  }
}

(. fooobar.com/questions/71374/...)

: customtab://www.myurl.example.com/, http://www.myurl.example.com https://www.myurl.example.com?

  • customtab:// customtabs://
  • URL customtab://http/www.myurl.example.com

, , , . :

public boolean shouldOverrideUrlLoading(WebView view, String url) {
  // TODO: start custom tabs for the url
  return true;
}
0

Source: https://habr.com/ru/post/1673066/


All Articles