0

What is the version of android from which external storage writing capability were introduced ?

Is it true that writing to external storage does not work for pre ICS devices ?

For me -

Reading data from external SD Card works fine.

But writing to external storage (SD Card), fails for my Ice Cream Sandwich device. It works fine for a Jelly Bean device.

logcat for error

11-15 12:35:41.249: D/dalvikvm(3467): GC_CONCURRENT freed 299K, 8% free 6260K/6791K, paused 2ms+3ms
11-15 12:36:01.629: W/System.err(3467): java.io.FileNotFoundException: /mnt/extsd/test/S1 Shakti/Vouchers/Out Vouchers/TabletTotest.xml: open failed: EACCES (Permission denied)
11-15 12:36:01.639: W/System.err(3467):     at libcore.io.IoBridge.open(IoBridge.java:406)
11-15 12:36:01.639: W/System.err(3467):     at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
11-15 12:36:01.639: W/System.err(3467):     at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
11-15 12:36:01.649: W/System.err(3467):     at test.mobility.utils.TFileMgr.Write(TFileMgr.java:180)
11-15 12:36:01.649: W/System.err(3467):     at test.mobility.app.PVPDataSync.GenertateTransactionXML(PVPDataSync.java:982)
11-15 12:36:01.649: W/System.err(3467):     at test.mobility.app.PVPDataSync.GenerateData(PVPDataSync.java:482)
11-15 12:36:01.649: W/System.err(3467):     at test.mobility.app.MainActivity$1.onClick(MainActivity.java:83)
11-15 12:36:01.649: W/System.err(3467):     at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
11-15 12:36:01.649: W/System.err(3467):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-15 12:36:01.649: W/System.err(3467):     at android.os.Looper.loop(Looper.java:137)
11-15 12:36:01.649: W/System.err(3467):     at android.app.ActivityThread.main(ActivityThread.java:4424)
11-15 12:36:01.659: W/System.err(3467):     at java.lang.reflect.Method.invokeNative(Native Method)
11-15 12:36:01.659: W/System.err(3467):     at java.lang.reflect.Method.invoke(Method.java:511)
11-15 12:36:01.659: W/System.err(3467):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-15 12:36:01.659: W/System.err(3467):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-15 12:36:01.659: W/System.err(3467):     at dalvik.system.NativeStart.main(Native Method)
11-15 12:36:01.659: W/System.err(3467): Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
11-15 12:36:01.659: W/System.err(3467):     at libcore.io.Posix.open(Native Method)
11-15 12:36:01.669: W/System.err(3467):     at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
11-15 12:36:01.669: W/System.err(3467):     at libcore.io.IoBridge.open(IoBridge.java:390)
11-15 12:36:01.669: W/System.err(3467):     ... 15 more
11-15 12:36:01.689: W/System.err(3467): java.io.FileNotFoundException: /mnt/extsd/test/S1 Shakti/Vouchers/Out Vouchers/TabletTotest.xml: open failed: EACCES (Permission denied)
11-15 12:36:01.689: W/System.err(3467):     at libcore.io.IoBridge.open(IoBridge.java:406)
11-15 12:36:01.689: W/System.err(3467):     at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
11-15 12:36:01.689: W/System.err(3467):     at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
11-15 12:36:01.689: W/System.err(3467):     at test.mobility.utils.TFileMgr.Write(TFileMgr.java:180)
11-15 12:36:01.689: W/System.err(3467):     at test.mobility.app.PVPDataSync.GenertateTransactionXML(PVPDataSync.java:982)
11-15 12:36:01.699: W/System.err(3467):     at test.mobility.app.PVPDataSync.GenerateData(PVPDataSync.java:482)
11-15 12:36:01.699: W/System.err(3467):     at test.mobility.app.MainActivity$1.onClick(MainActivity.java:83)
11-15 12:36:01.699: W/System.err(3467):     at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
11-15 12:36:01.699: W/System.err(3467):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-15 12:36:01.699: W/System.err(3467):     at android.os.Looper.loop(Looper.java:137)
11-15 12:36:01.699: W/System.err(3467):     at android.app.ActivityThread.main(ActivityThread.java:4424)
11-15 12:36:01.699: W/System.err(3467):     at java.lang.reflect.Method.invokeNative(Native Method)
11-15 12:36:01.699: W/System.err(3467):     at java.lang.reflect.Method.invoke(Method.java:511)
11-15 12:36:01.709: W/System.err(3467):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-15 12:36:01.709: W/System.err(3467):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-15 12:36:01.709: W/System.err(3467):     at dalvik.system.NativeStart.main(Native Method)
11-15 12:36:01.709: W/System.err(3467): Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
11-15 12:36:01.709: W/System.err(3467):     at libcore.io.Posix.open(Native Method)
11-15 12:36:01.709: W/System.err(3467):     at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
11-15 12:36:01.709: W/System.err(3467):     at libcore.io.IoBridge.open(IoBridge.java:390)
11-15 12:36:01.709: W/System.err(3467):     ... 15 more
11-15 12:36:01.919: W/System.err(3467): java.io.FileNotFoundException: /mnt/extsd/test/S1 Shakti/Vouchers/Out Vouchers/TabletTotest.xml: open failed: EACCES (Permission denied)
11-15 12:36:01.919: W/System.err(3467):     at libcore.io.IoBridge.open(IoBridge.java:406)
11-15 12:36:01.919: W/System.err(3467):     at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
11-15 12:36:01.929: W/System.err(3467):     at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
11-15 12:36:01.929: W/System.err(3467):     at test.mobility.utils.TFileMgr.Write(TFileMgr.java:180)
11-15 12:36:01.929: W/System.err(3467):     at test.mobility.app.PVPDataSync.GenertateTransactionXML(PVPDataSync.java:982)
11-15 12:36:01.939: W/System.err(3467):     at test.mobility.app.PVPDataSync.GenerateData(PVPDataSync.java:482)
11-15 12:36:01.939: W/System.err(3467):     at test.mobility.app.MainActivity$1.onClick(MainActivity.java:83)
11-15 12:36:01.939: W/System.err(3467):     at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
11-15 12:36:01.939: W/System.err(3467):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-15 12:36:01.949: W/System.err(3467):     at android.os.Looper.loop(Looper.java:137)
11-15 12:36:01.949: W/System.err(3467):     at android.app.ActivityThread.main(ActivityThread.java:4424)
11-15 12:36:01.949: W/System.err(3467):     at java.lang.reflect.Method.invokeNative(Native Method)
11-15 12:36:01.949: W/System.err(3467):     at java.lang.reflect.Method.invoke(Method.java:511)
11-15 12:36:01.959: W/System.err(3467):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-15 12:36:01.959: W/System.err(3467):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-15 12:36:01.959: W/System.err(3467):     at dalvik.system.NativeStart.main(Native Method)
11-15 12:36:01.959: W/System.err(3467): Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
11-15 12:36:01.969: W/System.err(3467):     at libcore.io.Posix.open(Native Method)
11-15 12:36:01.969: W/System.err(3467):     at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
11-15 12:36:01.969: W/System.err(3467):     at libcore.io.IoBridge.open(IoBridge.java:390)
11-15 12:36:01.979: W/System.err(3467):     ... 15 more
sunny
  • 1
  • 1
  • I have added permission in my app's Manifest android.permission.WRITE_EXTERNAL_STORAGE – sunny Nov 14 '13 at 14:54
  • you mush have the permision, otherwise you wouldnt be able to write in Jelly Bean. Please post the logcat message – SathMK Nov 14 '13 at 14:55
  • @SathMK `Environment.getExternalStoragePublicDirectory()` - this returns the path for non-removable storage and not the SD card path. I am trying by hardcoding the SD Card path and trying to write using `File`.[http://stackoverflow.com/questions/6049114/environment-getexternalstoragedirectory-does-not-return-the-path-to-the-removabl](http://stackoverflow.com/questions/6049114/environment-getexternalstoragedirectory-does-not-return-the-path-to-the-removabl) – sunny Nov 15 '13 at 07:16
  • you can do that from API level 1. Chech whether SD card is present and if it is there write to it using `File`. This post will help to determine whether the SD card is there or not http://stackoverflow.com/questions/7429228/check-whether-the-sd-card-is-available-or-not-programatically – SathMK Nov 15 '13 at 07:36

2 Answers2

0

If you haven't done so already, you will need to give your app the correct permission to write to the SD Card by adding the line below to your Manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Kuffs
  • 35,581
  • 10
  • 79
  • 92
0

You can write to SD card from API level 1. But API level 8 is required if you want to write to public directories like MUSIC,RINGTONES,etc... using the function Environment.getExternalStoragePublicDirectory().
How ever you can write to these directories using File.

SathMK
  • 1,171
  • 1
  • 8
  • 18