1

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

sumeet raj
  • 11
  • 4

2 Answers2

1

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

Aamil Silawat
  • 7,735
  • 3
  • 19
  • 37
0

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

Jai Khambhayta
  • 4,198
  • 2
  • 22
  • 29