0

I'm using Samsung J7 Unrooted for Testing,

My AndroidManifest.xml contains the necessary permissions to write to external storage

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

I don't encounter any error when I used the code:

File myFile = new File("sdcard/Billing/mysdfile.txt");

It save the file on the Device Storage. But when I specify the removable SDCard using the code:

File myFile = new File("/storage/extSdCard/mysdfile.txt");

I encounter the error : open failed: EACCES (Permission denied) I've tried different ways to point to the removable SDCard but encountered the same "open failed: EACCES (Permission denied)" error.

I've checked if I have the necessary permissions to write to external storages and it always say "Granted"

public void verifyStoragePermissions() {
    if (ContextCompat.checkSelfPermission(InitActivity.this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {
        Toast.makeText(getBaseContext(), "Denied", Toast.LENGTH_SHORT).show();
        if (ActivityCompat.shouldShowRequestPermissionRationale(InitActivity.this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

        } else {


        }
    }else{
        Toast.makeText(getBaseContext(), "Granted",Toast.LENGTH_SHORT).show();
    }
}

I've tried almost everything suggested listed in the google search but to no avail. There are a Few who advises to "Root" the phone but that is unfortunately not an option for me...

Hope someone can help me gain the needed permission rights to save files in my removable external storage without resorting to "Rooting" the phone.

  • Unfortuneately, the path to the SDcard storage differs between manufacturers. See http://stackoverflow.com/questions/23123461/ for more info. – Remy Lebeau Mar 16 '16 at 03:35
  • Can you show your logcat – mr.icetea Mar 16 '16 at 03:53
  • @RemyLebeau , I already have the correct path of the removable external sdcard because the error would be "open failed: ENOENT(No such file or directory". For now, I just want to solved the permission problem, I'm encountering short of Rooting the Phone, and Adding to the System/etc/permissions - "Write_External_Storage". – Tony Mercado Mar 16 '16 at 05:17
  • @mr.icetea , nothing shows in the logcat with regards to the denied permission... – Tony Mercado Mar 16 '16 at 05:20
  • Try this : [permission check sample](http://stackoverflow.com/a/36031791/968538) – Christian Mar 16 '16 at 10:43

0 Answers0