Skip to content Skip to sidebar Skip to footer

What Is The Intent To Launch Any Website Link In Google Chrome

Hi I want to open the website in chrome app from my app webview when user click on particular link. I see this is possible https://developer.chrome.com/multidevice/android/intents,

Solution 1:

It seems you're looking for the new Android Intents link that will create and explicit intent for the device for a link.

<ahref="intent://<URL>#Intent;scheme=http;package=com.android.chrome;end">

works for me. so

<ahref="intent://stackoverflow.com/questions/29250152/what-is-the-intent-to-launch-any-website-link-in-google-chrome#Intent;scheme=http;package=com.android.chrome;end">

will take you to this question in Chrome. Note that the scheme is specified separately so if you want to launch https links, you'd have to change scheme to scheme=https

But as everyone is saying, an explicit Chrome intent is a very non-Android thing to do. A better way would be to specify the ACTION_VIEW action like so:

<ahref="intent://stackoverflow.com/questions/29250152/what-is-the-intent-to-launch-any-website-link-in-google-chrome#Intent;scheme=http;action=android.intent.action.VIEW;end;">

Source: The same page you linked

Thanks, I learned something today!

Solution 2:

Below code make launch urls in webview including intent:// url scheme in Android.

@OverridepublicbooleanshouldOverrideUrlLoading(WebView view, String url) {
    if (url != null) {
        if (url.startsWith("http://") || url.startsWith("https://")) {
            view.loadUrl(url);
        } elseif (url.startsWith("intent://")) {
            try {
                Intentintent= Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
                IntentexistPackage= getPackageManager().getLaunchIntentForPackage(intent.getPackage());
                if (existPackage != null) {
                    startActivity(intent);
                } else {
                    IntentmarketIntent=newIntent(Intent.ACTION_VIEW);
                    marketIntent.setData(Uri.parse("market://details?id=" + intent.getPackage()));
                    startActivity(marketIntent);
                }
                returntrue;
            } catch (Exception e) {
                e.printStackTrace();
            }
        } elseif (url.startsWith("market://")) {
            try {
                Intentintent= Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
                if (intent != null) {
                    startActivity(intent);
                }
                returntrue;
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        } else { // unhandled url scheme
             view.getContext().startActivity(
                    newIntent(Intent.ACTION_VIEW, Uri.parse(url)));
        }
        returntrue;
    } else {
        returnfalse;
    }
}

Solution 3:

I have tested below code with Nexus 6 with Chrome and Mozilaa installed and it works great,

Stringurl="http://www.stackoverflow.com";
    Intenti=newIntent();
    i.setPackage("com.android.chrome");
    i.setAction(Intent.ACTION_VIEW);
    i.setData(Uri.parse(url));
    startActivity(i);

This will give error if Chrome is not installed in your device. So put check for package availability.

Solution 4:

Use this:

Stringurl="http://www.example.com";
Intenti=newIntent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);

hope this will help..

Solution 5:

This code is to open an android application from your chrome browser. You can check this from this link

<ahref="intent://scan/#Intent;scheme=zxing;package=com.google.zxing.client.android;end"> Take a QR code </a>

I am having another way of opening Chrome browser from your application

privateclassMyWebViewClientextendsWebViewClient {

publicbooleanshouldOverrideUrlLoading(WebView paramWebView, String paramString) {

   Stringurl= Uri.parse(paramString);
   try {
       Intenti=newIntent("android.intent.action.MAIN");
       i.setComponent(ComponentName.unflattenFromString
                      ("com.android.chrome/com.android.chrome.Main"));
       i.addCategory("android.intent.category.LAUNCHER");
       i.setData(Uri.parse(url));
       startActivity(i);
   } catch(ActivityNotFoundException e) {
       // Chrome is not installedIntenti=newIntent(Intent.ACTION_VIEW, Uri.parse(url));
       startActivity(i);
   }
  }
}

Post a Comment for "What Is The Intent To Launch Any Website Link In Google Chrome"