Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get my Android device Internal Download Folder path? [duplicate]

It is possible to get the Android device Internal Download Folder path?

like image 915
Andrey Avatar asked Feb 12 '14 10:02

Andrey


People also ask

How do I find the download path on Android?

To see the location of your Download folder, tap the three-dot menu next to one of your downloaded files and go to File info. The /storage/emulated/0/Download path is the default for many modern Android devices.

How do I find my download path?

The file path for your downloaded files (for example, C:\Users\[your name]\Downloads) is listed under Location. In Microsoft Edge Legacy , select Settings and more > Settings . Then scroll down to the Downloads section.

Where can I find internal files on Android?

The exact location of the data stored on an Android phone may vary in different models and versions. But in most cases, you can see the internal storage of an Android phone: Navigate to My Files to view internal storage as well as SD card and Network storage. Here, tap Internal Storage to see your files and folders.


1 Answers

If a device has an SD card, you use:

Environment.getExternalStorageState() 

If you don't have an SD card, you use:

Environment.getDataDirectory()

If there is no SD card, you can create your own directory on the device locally.

    //if there is no SD card, create new directory objects to make directory on device
        if (Environment.getExternalStorageState() == null) {
                        //create new file directory object
            directory = new File(Environment.getDataDirectory()
                    + "/RobotiumTestLog/");
            photoDirectory = new File(Environment.getDataDirectory()
                    + "/Robotium-Screenshots/");
            /*
             * this checks to see if there are any previous test photo files
             * if there are any photos, they are deleted for the sake of
             * memory
             */
            if (photoDirectory.exists()) {
                File[] dirFiles = photoDirectory.listFiles();
                if (dirFiles.length != 0) {
                    for (int ii = 0; ii <= dirFiles.length; ii++) {
                        dirFiles[ii].delete();
                    }
                }
            }
            // if no directory exists, create new directory
            if (!directory.exists()) {
                directory.mkdir();
            }

            // if phone DOES have sd card
        } else if (Environment.getExternalStorageState() != null) {
            // search for directory on SD card
            directory = new File(Environment.getExternalStorageDirectory()
                    + "/RobotiumTestLog/");
            photoDirectory = new File(
                    Environment.getExternalStorageDirectory()
                            + "/Robotium-Screenshots/");
            if (photoDirectory.exists()) {
                File[] dirFiles = photoDirectory.listFiles();
                if (dirFiles.length > 0) {
                    for (int ii = 0; ii < dirFiles.length; ii++) {
                        dirFiles[ii].delete();
                    }
                    dirFiles = null;
                }
            }
            // if no directory exists, create new directory to store test
            // results
            if (!directory.exists()) {
                directory.mkdir();
            }
        }// end of SD card checking

add permissions on your manifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
like image 129
4 revs, 3 users 94% Avatar answered Sep 21 '22 02:09

4 revs, 3 users 94%