sumeet raj
sumeet raj

Reputation: 11

Get external storage path in android app for tablet

How can i show all external storage in spinner and access only external storage on selection from spinner for tablet in android app programmatically

Upvotes: 1

Views: 1507

Answers (2)

Aamil Silawat
Aamil Silawat

Reputation: 8229

For getting External Storage Path Environment.getExternalStorageState()

final String state = Environment.getExternalStorageState();

if ( Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state) ) {  // we can read the External Storage...           
    //Retrieve the External Storage:
    final File primaryExternalStorage = Environment.getExternalStorageDirectory();

    //Retrieve the External Storages from the root directory:
    final String externalStorageRootDir;
    if ( (externalStorageRootDir = primaryExternalStorage.getParent()) == null ) {  
        Log.d(TAG, "External Storage: " + primaryExternalStorage + "\n");
    }
    else {
        final File externalStorageRoot = new File( externalStorageRootDir );
        final File[] files = externalStorageRoot.listFiles();

        for ( final File file: files ) {
            if ( file.isDirectory() && file.canRead() && (file.listFiles().length > 0) ) {  // it is a directory (not a External drive)...
                Log.d(TAG, "External Storage: " + file.getAbsolutePath() + "\n");
            }
        }
    }
}

For more Info Try this link Find location of a removable SD card

Upvotes: 1

Jaydeep Khambhayta
Jaydeep Khambhayta

Reputation: 5279

Try this lib maybe help you. File and folder picker

 dependencies {
      compile 'com.github.isabsent:filepicker:1.1.01'
   }

https://github.com/isabsent/FilePicker?utm_source=android-arsenal.com&utm_medium=referral&utm_campaign=6975

Upvotes: 0

Related Questions