سؤال

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top