I have easily accessed Internal Storage Files using
File internalStorage = new File( Environment.getExternalStorageDirectory().getAbsolutePath() );
internalStorage.listFiles();
And i am getting all the files. But i am unable to get any file from my mounted sd-card. i have checked. if SD-Card is mounted
boolean isSdCard = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
And i have also tried different solutions like.
File sdCardFolder = new File(System.getenv("SECONDARY_STORAGE"));
//RESULT.
sdCardFolder.getName() //sdcard0.
sdCardFolder.listFile() //null.
Here it's giving the folder name but sending null for listFile.
And also i have tried different other methods to listFiles from my SD Card but unable to find a working one.
in build.gradle.
compileSdkVersion 31.
targetSdkVersion 31
Check and ask for permission to access external cards in your manifest or by code