How can i show all external storage in spinner and access only external storage on selection from spinner for tablet in android app programmatically
Asked
Active
Viewed 1,469 times
1
-
`Environment.getExternalStorageDirectory()` to get the path to external storage – keser Dec 13 '19 at 09:55
-
@keser `getExternalStorageDirectory()` has been deprecated. – Sam Chen Sep 03 '20 at 17:36
2 Answers
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'
}

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