I installed the following android manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
My activities include the following:
File sd = Environment.getExternalStorageDirectory(); boolean can_write = sd.canWrite();
sd returns / mnt / sdcard
I am testing my device (evo 3d), not an emulator. SD card installed. This happens both in charger mode and when the USB cable is not connected. The various pages on google and the messages on the stack show the same method to check if the SD card is writable, so I am missing something.
UPDATE:
I try the following code and it refuses to resolve ioexception.
File TestFile = new File(sd + "/testfile.txt"); try { boolean result = TestFile.createNewFile(); if(result) { Log.i("tag","successfully created file"); } else { Log.i("tag","failed to create file"); } } catch (IOException e) { Log.e("tag",e.toString() + " " + TestFile); return false; }
I formatted my SD card, mounted it again and rebooted the phone and still had the same error.
UPDATE
Apparently, it was my ignorance that made him fail. I had a permission block in the wrong section of my manifest. Thanks again:)
source share