How to open default gallery app with particular album or folder?

寵の児 提交于 2020-08-25 07:29:08

问题


Every example i found on net is opening gallery and get images from gallery as result. My need is i don't want result or images to my app. I just want to trigger gallery app with showing particular folder of images. My App Have separate folder to save images. i need to navigate users directly to that path.


回答1:


Try this code. It will retrieve view pictures under storage/emulated/0/Pictures/AppPics You can change the file path according to your directory path.

File sdDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File file = new File(sdDir, "AppPics");

if (file.isDirectory()) 
    listFile = file.listFiles();

EDIT: To open your folder using intent

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.withAppendedPath(Uri.fromFile(file), "/AppPics"), "image/*");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);



回答2:


You can try like this,

Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = [Uri for your folder];
intent.setDataAndType(uri, "image/*");
startActivity(Intent.createChooser(intent, "Open [App] images"));


来源:https://stackoverflow.com/questions/44858799/how-to-open-default-gallery-app-with-particular-album-or-folder

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