Is There Any Way in Android to Force Open a Link to Open in Chrome

Is there any way in Android to force open a link to an external browser?

Your implementation looks good to me and you can use it whether chrome is installed or not but you need to check if it is resolvable or not:

if (url != null) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}

If you want to show list of browsers to user to choose from you can use:

Intent sendIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
Intent chooser = Intent.createChooser(sendIntent, "Choose Your Browser");
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}

If your targetSdk is 30 or above take a look at this document too:
https://developer.android.com/training/package-visibility/use-cases

How can I open a URL in Android's web browser from my application?

Try this:

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);

That works fine for me.

As for the missing "http://" I'd just do something like this:

if (!url.startsWith("http://") && !url.startsWith("https://"))
url = "http://" + url;

I would also probably pre-populate your EditText that the user is typing a URL in with "http://".

Is there any way to force a link to open in Chrome from Facebook's in-app browser?

Try

googlechrome://navigate?url=example.com

for Android users.

Reference from https://stackoverflow.com/a/12013755/9514189



Related Topics



Leave a reply



Submit