I'm trying to open up a Chrome custom tab from within a webview inside of an Android app.   In order to do this, I figured I could register a custom URL handler(customtab://www.myurl.com/). The error I'm running into is that chromium(the webview) is blocking the custom URL handler due to an insecure content error (This request has been blocked; the content must be served over HTTPS.).  The URL is https.   Even adding webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); on the webView didn't work.
Any ideas on how I can register this custom handler as "secure"?
4 Answers
Answers 1
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);
Answers 2
You need to override this method on the Webview to skip ssl errors
public synchronized void onReceivedSslError(WebView view, final SslErrorHandler handler,SslError error) {         handler.proceed();                             }      Answers 3
I am open my custom URL in web view in android with follow below process.
Design your webview as full screen like
<?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>   And in you .java file add below code in onCreate method
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();         }   If still any issue please provide me your url I'll check and provide you the code.
Hope your problme resolve.
Make sure provide permission in Manifest file.
"<"uses-permission android:name="android.permission.INTERNET" />" (remove the quatation mark)
Answers 4
You simply need to register a WebViewClient in your WebView and override the shouldOverrideUrlLoading() method to support your own scheme:
public boolean shouldOverrideUrlLoading(WebView view, String url) {   if (url.startsWith("custometab://")) {     // TODO: start custom tabs for the url.     return true;   } else {     return false;   } }   (see http://stackoverflow.com/a/5514668/94363)
The problem is: how do you know when clicking on customtab://www.myurl.example.com/ if you should open http://www.myurl.example.com or https://www.myurl.example.com?
- You could either introduce 
customtab://andcustomtabs:// - or do some manipulation of the URL 
customtab://http/www.myurl.example.com 
But in fact, I don't think we need a custom scheme at all if you want to open all links with custom tabs. Just use:
public boolean shouldOverrideUrlLoading(WebView view, String url) {   // TODO: start custom tabs for the url   return true; }      
0 comments:
Post a Comment