I have checked the below code
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
Log.d("StatusActivity", "sdcard mounted and writable");
}
else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
Log.d("StatusActivity", "sdcard mounted readonly");
}
else {
Log.d("StatusActivity", "sdcard state: " + state);
}
The output shows sdcard mounted and writable
But the Environment.getExternalStorageDirectory().canWrite()
always returns false. Can anyone advise?
You need WRITE_EXTERNAL_STORAGE permission for your app. In addition, if you're writing a file that's being used only by your app, you should store it in Context.getExternalFilesDir(), to prevent spreading your app's files throughout public storage. If you are writing a public file, you should store it in Environment.getExternalStoragePublicDirectory().
Check if your device has enough storage space. That could also be the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With