I have referred this guide.
I want to create one folder say "XYZ" on the root of sdcard. So consider the following code: (XYZ folder does not exist on internal or external sd card)
private void aaskForAppyStoreFolderPermission(){
if(FWCompat.isNougat_24_OrNewer()){
StorageManager sm = (StorageManager)getSystemService(Context.STORAGE_SERVICE);
File f = new File("/XYZ");
StorageVolume extStorage = sm.getStorageVolume(f);
if(extStorage != null) {
Intent intent = extStorage.createAccessIntent(null);
startActivityForResult(intent, 100);
}
}
}
But this does not show any popup for accessing XYZ folder. Now even if I create a folder manually and try again with "/XYZ" or "/storage/emulated/0" or "/storage/459-C045/XYZ" path. It still does not work.
But if I try to get access for whole external memory card : as following then it shows the popup but the message says that do you wish to grant access the complete sd card (which is correct but not what I need. As I want access to only one particular folder (which may or may not exist)) The code to get access to whole memory card:
private void askForAppyStoreFolderPermission(){
if(FWCompat.isNougat_24_OrNewer()){
StorageManager sm = (StorageManager)getSystemService(Context.STORAGE_SERVICE);
List<StorageVolume> volumeList = sm.getStorageVolumes();
if(volumeList != null && volumeList.size() > 0){
StorageVolume extStorage = volumeList.get(volumeList.size() - 1);
if(extStorage != null) {
Intent intent = extStorage.createAccessIntent(null);
startActivityForResult(intent, 100);
}
}
}
}