'Path to screenshots in Android

Is there a way to find out the path used by android to save screenshots?

Can I get the path from a code?



Solution 1:[1]

Android's API has no fixed path for screenshots but

File pix = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File screenshots = new File(pix, "Screenshots");

might work. That's what ICS uses as path.

Solution 2:[2]

The "Screenshots" value is part of the private API.

Here is link to the source code where the value is set. Since the class is loaded in our application context there is no option to access the field. I'd hardcode it as @zapi suggested.

Solution 3:[3]

Few might find this usefull..

 public static File mDir= new File(String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)));
 public static File mDirScreenshots = new File(mDir,"Screenshots");

And to fetch the screenshots

 public static ArrayList<File> getAllScreenshots(File dir){
    File listFile[] = dir.listFiles();
    if (listFile != null && listFile.length > 0) {
        for (int i = 0; i < listFile.length; i++) {
            Log.e(YOUR_TAG, "getAllScreenshots: " + i + listFile[i].getName());
            mScreenshotsFiles.add(listFile[i]);
        }
    }
    return mScreenshotsFiles;
}

Solution 4:[4]

Recursion is your friend here. Tested on Android version 9 and 12. Works good.

final String findThisDirectory = "screenshots";
final String rootPath = Environment.getExternalStorageDirectory().getPath();

//we do not want to include 'Android' directory because looking inside it
//or some directories inside of it can and will cause crash in some Android versions due to permissions related issues
String ignoreThisDirectory = "android";

void getPathRecursively(String rootPath, String matchThisDirectory, String ignoreThisDirectory){
    File[] filesArray = new File(rootPath).listFiles();
    if(filesArray.length > 0){
        for(File file: filesArray){
            if(file.isDirectory()){
                if(file.getName().toLowerCase().equals(ignoreThisDirectory)){
                    continue;
                }
                else if(file.getName().toLowerCase().equals(matchThisDirectory)){
                    // here you found the path to 'screenshots' in file object
                    // get it from the file.getAbsolutePath()
                    break;
                }
                getPathRecursively(file.getAbsolutePath(), matchThisDirectory, ignoreThisDirectory);
            }
        }
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zapl
Solution 2 Rudy Rudolf
Solution 3 Prashant
Solution 4 falero80s