Open Chrome app with url

Is there a way to open the Chrome app on Android from the default Android browser? I can open the application, but it does not redirect the user to the correct page. This is what I tried:

<a href="googlechrome://www.toovia.com"> 

I saw that I might have to create an intent URL, but I was hoping there was a much easier way than that.

This is supposed to be from a webpage and there is no webview.

+8
source share
6 answers

Yes, but if it is not installed on the system, you will encounter an ActivityNotFoundException. If it is not available, you must run it through a regular browser:

 String url = "http://mysuperwebsite"; try { Intent i = new Intent("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 installed Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(i); } 
+11
source

Here is a solution without try catch, if Chrome is installed, it will be used. Otherwise, it will go to the default device

 void open(Activity activity, String url) { Uri uri = Uri.parse("googlechrome://navigate?url=" + url); Intent i = new Intent(Intent.ACTION_VIEW, uri); if (i.resolveActivity(activity.getPackageManager()) == null) { i.setData(Uri.parse(url)); } activity.startActivity(i); } 
+8
source

I opened the Safe Browser application with the package name from the Google game, just like the default for Chrome:

 Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://Your URL")); intent.setPackage("com.cloudacl"); // package of SafeBrowser App startActivity(intent); 

You can replace the com.cloudacl package with this com.android.chrome to open chrome.

+1
source

Best Detect Custom Browser

 alert(navigator.userAgent); 

and depending on the conditional statement

 if (navigator.userAgent.indexOf('foo')) { // code logic } 

and based on this use the BOM API to update the location of the window

 window.location.href = 'googlechrome://navigate?url='+ link; 
+1
source

Your xml:

 <?xml version="1.0" encoding="utf-8"?> <WebView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/webView1" android:layout_width="fill_parent" android:layout_height="fill_parent" /> 

Your WebViewActivity :

 public class WebViewActivity extends Activity { private WebView webView; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.webview); webView = (WebView) findViewById(R.id.webView1); webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl("http://www.google.com"); } } 
0
source

Intent solutions no longer work.

The following works for me ..

document.location = 'googlechrome: // navigate? url = www.tovia.com/ ';

0
source

All Articles