How to get the path of a specific folder in Android Q

為{幸葍}努か 提交于 2021-02-04 19:40:27

问题


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;
    }

来源:https://stackoverflow.com/questions/57451973/how-to-get-the-path-of-a-specific-folder-in-android-q

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