Reputation: 3789
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?
Upvotes: 5
Views: 2964
Reputation: 52366
Check if your device has enough storage space. That could also be the problem.
Upvotes: 1
Reputation: 8641
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().
Upvotes: 6