0

引入外部存储写入功能的 android 版本是什么?

对 ICS 之前的设备来说,写入外部存储是真的吗?

为了我 -

从外部 SD 卡读取数据工作正常。

但是我的冰淇淋三明治设备写入外部存储(SD 卡)失败。它适用于 Jelly Bean 设备。

logcat 错误

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
4

2 回答 2

0

如果您还没有这样做,则需要通过将以下行添加到您的清单中,为您的应用授予正确的写入 SD 卡的权限:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
于 2013-11-14T14:45:23.897 回答
0

您可以从API level 1. 但是API level 8,如果您想使用该功能写入 MUSIC、RINGTONES 等公共目录,则需要Environment.getExternalStoragePublicDirectory()
您如何使用File.

于 2013-11-14T14:54:47.193 回答