Domanda

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?

È stato utile?

Soluzione

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().

Altri suggerimenti

Check if your device has enough storage space. That could also be the problem.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top