Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing "open with" dialog on Android

Tags:

android

mobile

How can I give chance to user to choose application for opening a link?

For example, user has 3 browsers and he set Firefox as default browser. I want to give chance to open a link with Opera to user when user long click link.

like image 434
Murat Çorlu Avatar asked Aug 17 '11 06:08

Murat Çorlu


2 Answers

Try using Intent.createChooser:

Uri uri = Uri.parse( "http://www.google.com" );
startActivity(Intent.createChooser(new Intent(Intent.ACTION_VIEW, uri), "Choose browser"));
like image 139
Flavio Avatar answered Oct 19 '22 19:10

Flavio


PackageManager.queryIntentActivities() returns all of the activities that can handle a particular Intent.

With the Intent you passed in to it, to now use it to launch one of the activities in the returned list, you use Intent.setComponent with a ComponentName built from the packageName and name of the activity you want in that list.

like image 33
hackbod Avatar answered Oct 19 '22 18:10

hackbod