I am trying to read and write to external storage in Android 7. I am using the following code to check the read and write status.
public void checkStorage() {
File sd = Environment.getExternalStorageDirectory();
if (sd.canWrite() && sd.canRead())
Toast.makeText(context, "sd can read and write", Toast.LENGTH_LONG).show();
else if (sd.canWrite() && !sd.canRead())
Toast.makeText(context, "sd cannot read but write", Toast.LENGTH_LONG).show();
else if (!sd.canWrite() && sd.canRead())
Toast.makeText(context, "sd can read but not write", Toast.LENGTH_LONG).show();
else if (!sd.canWrite() && !sd.canRead())
Toast.makeText(context, "sd cannot read and write", Toast.LENGTH_LONG).show();
}
I have also mentioned both the permissions in manifest file which are
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
but still I am getting that sd(external) storage is neither readable nor writable. Has anybody encountered such a problem? I am out of ideas how to solve the issue.