Open a specific folder inside gallery android

不问归期 提交于 2019-12-12 09:56:45

问题


I have a camera app which save image to separate folder inside the gallery. Path to my folder is /storage/emulated/0/Pictures/CameraExample/

When I click on the button I need to open the folder where I have saved the images. I have used all the solution which was available.

This how I'm reading the path. Let me know if i'm wrong.

String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath();
        Log.d("HelperUtils . getFilePaths", "setting the path " + path);
        String targetPath = path +"/CameraExample/";

How to start a new Intent and open the files?


回答1:


You can list all files which exist in your directory like this

File[] listFile;
File file = new File(android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "CameraExample");
if (file.isDirectory()) 
        listFile = file.listFiles();

Then you can display those images using GridView or however you want.

EDIT: To open your folder using intent

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath()
+ "/CameraExample/");
intent.setDataAndType(uri, "*/*");
startActivity(Intent.createChooser(intent, "Open folder"));


来源:https://stackoverflow.com/questions/28195788/open-a-specific-folder-inside-gallery-android

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