Launching Gallery in android phones

纵饮孤独 提交于 2019-12-01 10:30:18

You should be able to start the Gallery app via a basic Intent like this:

Intent intent =  new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivity(intent);

It may fire the app picker if more than one app is able to let you display images (e.g. Gallery and ESFileExplorer).

There is no universal table describing the "Gallery" app on every Android device, so the best you can do to avoid showing the user the activity resolver is to list all of the possible activity handlers programmatically and make an informed guess about which one to launch.

PackageManager.queryIntentActivities turns an Intent into such a list of packages as long as you seed the Intent with the type of file to open:

Intent newIntent = new Intent(Intent.ACTION_VIEW);
newIntent.setType("image/*");
List<ResolveInfo> allHandlers = pm.queryIntentActivities(newIntent, PackageManager.MATCH_DEFAULT_ONLY);

You could then trawl this list for known packages (from your list above) or, failing that, launch the first one in the list.

However, you should consider making a trivial Activity of your own to display the image. That is the only way to gain the level of control you seek.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!