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
How to Implement Drag and Drop in Android 2.2
How to Make Custom Dialog with Rounded Corners in Android
How to Represent a "Many to Many" Relation with Android Room When Column Names Are Same
Android Background Image Memory Usage
"Canvas: Trying to Draw Too Large Bitmap" When Android N Display Size Set Larger Than Small
Flutter Projects & Android X Migration Issues
Android:Get View Reference to a Menu Item
Override Android Backbutton Behavior Only Works on the First Page with Phonegap
How to Evenly Distribute Buttons Across the Width of a Linearlayout
"Failure Delivering Result " - Onactivityforresult
Refresh Fragment UI from Fragmentactivity
Integrate Zxing in Android Studio
Memory Leaks with Custom Font for Set Custom Font
Lazy Load Images on Listview in Android(Beginner Level)
Detect Touch Event on a View When Dragged Over from Other View