2

I'm trying to display all images saved on a specific folder on the gallery, in Android Q getExternalStoragePublicDirectory method is deprecated and not working, How can I get the path of a folder in Android Q?

@Override
    protected ArrayList<Photo> doInBackground(Void... voids) {
        ArrayList<Photo> photo = new ArrayList<>();
        File downloadsFolder = null;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            //
        } else {
            downloadsFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES + "/FolderName");
        }
        Photo s;
        if (downloadsFolder != null && downloadsFolder.exists()) {
            File[] files = downloadsFolder.listFiles();
            if (files != null) {
                for (File file : files) {
                    s = new Photo();
                        s.setName(file.getName());
                        s.setUri(Uri.fromFile(file));
                        photo.add(s);
                }
            }
        }
        return photo;
    }
  • "How can I get the path of a folder in Android Q?" -- as I mentioned [here](https://stackoverflow.com/questions/57357175/how-to-save-image-to-camera-folder-in-android-q?noredirect=1#comment101378552_57357175), there is no filesystem path that you can use. You would need to query the `MediaStore`. – CommonsWare Aug 11 '19 at 17:03
  • @CommonsWare, thank you, but how I can do this – Mouaad Abdelghafour AITALI Aug 11 '19 at 17:10
  • 1
    You use `ContentResolver` and `query()` to query the `MediaStore` in general -- there are lots of examples of this here on Stack Overflow. For images being stored using [techniques like this](https://stackoverflow.com/q/57357175/115145), you should be able to include `RELATIVE_PATH` in your query projection, then use that to identify the ones that are in the location that interests you. – CommonsWare Aug 11 '19 at 17:19

0 Answers0