开发者

Showing "open with" dialog on Android

开发者 https://www.devze.com 2023-03-29 03:11 出处:网络
How can I give chance to user to choose application for opening a link? For e开发者_StackOverflow中文版xample, user has 3 browsers and he set Firefox as default browser. I want to give chance to open

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

For e开发者_StackOverflow中文版xample, 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.


Try using Intent.createChooser:

Uri uri = Uri.parse( "http://www.google.com" );
startActivity(Intent.createChooser(new Intent(Intent.ACTION_VIEW, uri), "Choose browser"));


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.


You can create a Uri with your URL and pass it to an Intent like so:

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

Is this what you're looking to accomplish?

0

精彩评论

暂无评论...
验证码 换一张
取 消