Reputation: 99
Android Studio newbie here. I have a project where when a button is pressed, it must ask the user where they would like the link to open: my phone's default browser or another application MyBrowser(where it will open the browser through MyBrowser). However, when I press the button, it automatically takes me to just my phone's default browser without giving the user the opportunity to choose. Here is my code:
openWeb = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.amazon.com"));
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("browser.school.mybrowser");
Intent chooser = Intent.createChooser(openWeb, "Please choose which browser...");
if (openWeb != null) {
startActivity(chooser);
}
if (launchIntent != null) {
startActivity(launchIntent);
}
Upvotes: 0
Views: 186
Reputation: 2439
You have to add an intent filter to the activity to handle the request in the app manifest file. check here
Upvotes: 1