0

I have an application in which I want to write a file to SD Card.

the path to SD card is

/mnt/extsd

When I try to create a file or a directory using mkdirs() it returns false.

I am also getting

open failed: EACCES (Permission denied)

I have ES File explorer installed in my tablet. It is able to copy files to sd card. I don't know how it may be doing.

Please help !! Thanks in advance.

bhavindesai
  • 799
  • 7
  • 7
  • 2
    have you added permission in manifest file – Raghunandan Jan 15 '14 at 07:52
  • 1
    Yes I have also added permission It is out of scope. When I do Environment.getExternalStorageDirectory() it returns me the path of "/mnt/sdcard" which is internal memory(not phone memory) I want to write to external SD Card – bhavindesai Jan 15 '14 at 07:53
  • its external storage. you can't do much about it. Your phone memory has a external storage. the path returned is the path of external storage. There is a workaround which is not recommended – Raghunandan Jan 15 '14 at 08:00
  • Can you provide the workaround ? hope it is helpful – bhavindesai Jan 15 '14 at 08:02
  • you can check this http://stackoverflow.com/questions/15744064/cant-check-if-file-on-sdcard-exists. but this is not the recommended way and may not work well – Raghunandan Jan 15 '14 at 08:03
  • @Raghunandan checkout my answer. I think that is the issue. – mn0102 Jan 15 '14 at 12:14

3 Answers3

1

Edit:

Use

String extsdPath = System.getenv("SECONDARY_STORAGE"); // will return you /mnt/extsd/

Even after then,

Go to terminal hit "ls -l /mnt/" command in adb shell if

d---rwxr-x system   media_rw          1970-01-01 05:30 extsd
d---rwxr-x system   sdcard_rw          1970-01-01 05:30 sdcard

if its of media_rw group then your application does not have permissions to write "/mnt/extsd/". The permission is granted only to the system applications. This is a reported bug to Google.

Reference link: google group post

mn0102
  • 839
  • 1
  • 12
  • 25
  • this is not the issue here. op says in comment "it returns me the path of "/mnt/sdcard"" . so the path returned is correct – Raghunandan Jan 15 '14 at 12:15
  • Lets have bhavin to comment on this. There's nothing else than this. :) – mn0102 Jan 15 '14 at 12:35
  • then why did you ping me and asked me to check your answer. leave to op to decide whether he wants to accept or not. :) – Raghunandan Jan 15 '14 at 12:38
  • I'am sorry that I asked you. – mn0102 Jan 15 '14 at 12:40
  • Thank you guys for your efforts. @aditya I know what you said but still that doesn't solves my query. I have same permissions as you mentioned in your answer and if we assume that the external SD Card is just read only then how it is possible for ES File Explorer app to copy files. Ultimately while copying file the app must create a file and then copy the the bytes. – bhavindesai Jan 16 '14 at 11:27
  • android.permission.WRITE_MEDIA_STORAGE, SuppressLint the error which will occur saying Permission is granted only for the System Applications. And then try running it. – mn0102 Jan 16 '14 at 13:20
  • @aditya - that permission won't work unless is the poster is able to install as a system app – Chris Stratton Mar 14 '14 at 20:27
  • @ChrisStratton yes. Hope ODM's would understand this thing. – mn0102 Mar 18 '14 at 09:44
1

the problem is with jelly bean

this work for me

String path = null;
      if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT){
          path = getCacheDir() + File.separator + "name";
         } else{
          path = Environment.getExternalStorageDirectory() + File.separator + "name";
         }
Maher Tag
  • 219
  • 1
  • 3
  • 14
0

give perms to /mnt/media_rw/external_SD:

mount -o remount,rw /   
chmod 770 /mnt/media_rw/.   
mount -o remount,ro /   
uli
  • 1