Reputation: 11
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
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
Reputation: 5279
Try this lib maybe help you. File and folder picker
dependencies {
compile 'com.github.isabsent:filepicker:1.1.01'
}
Upvotes: 0