对应Android 1.5以上的版本中一定要在AndroidManifest.xml中加入:<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> 并且你要确认你的SD卡的读写权限打开的。然后 写入SD卡:File f = new File(android.os.Environment.getExternalStorageDirectory()+"/test.txt"); String str="this is a test about Write SD card file";写入方法: FileOutputStream fileOS=new FileOutputStream(f); fileOS.write(str.getBytes()); fileOS.close(); BufferedWriter buf = new BufferedWriter (new OutputStreamWriter(fileOS)); buf.write(str,0,str.length()); buf.flush(); buf.close();
SD卡对system用户没有读写的权限,你可以用 ls -l查看一下,如下: d---rwxr-x system sdcard_rw 2010-07-26 12:56 sdcard 我也在被这个问题困扰着,期待高人能找到方法
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 只加上这个就行不需要android.uid.systemd---rwxrwx system system 2010-07-28 11:11 sdcard 这是sdcard的权限读写都可以的
Processes that continue holding open fds on the sdcard a little after it is requested to be unmounted will be killed so that it can unmount. We don't want the system process to be able to access the sdcard to avoid these kinds of issues (and just general security cleanliness), so that it does not have permission to access it. 从上面可以看出,system process是不允许操作sdcard的,有个办法是,可以借助一个运行在user process中的activity helper类完操作sdcard的动作
并且你要确认你的SD卡的读写权限打开的。然后
写入SD卡:File f = new File(android.os.Environment.getExternalStorageDirectory()+"/test.txt");
String str="this is a test about Write SD card file";写入方法:
FileOutputStream fileOS=new FileOutputStream(f);
fileOS.write(str.getBytes());
fileOS.close();
BufferedWriter buf = new BufferedWriter (new OutputStreamWriter(fileOS));
buf.write(str,0,str.length());
buf.flush();
buf.close();
d---rwxr-x system sdcard_rw 2010-07-26 12:56 sdcard
我也在被这个问题困扰着,期待高人能找到方法
就可以了,不需要加上android.uid.system,如果加了这个,就肯定是没有权限读写的。
只加上这个就行不需要android.uid.systemd---rwxrwx system system 2010-07-28 11:11 sdcard
这是sdcard的权限读写都可以的
1.假如我现在一个app需要获得系统权限,就是说要加上android.uid.system,同时想能读写sdcard卡,该如何实现呢!?
2.另外如何看一个app是运行在哪个uid下的?没有源码情况下。
1.假如我现在一个app需要获得系统权限,就是说要加上android.uid.system,同时想能读写sdcard卡,该如何实现呢!?
这个问题解决了吗?
Setings中就是这种情况
requested to be unmounted will be killed so that it can unmount.
We don't want the system process to be able to access the sdcard to avoid
these kinds of issues (and just general security cleanliness), so that it
does not have permission to access it. 从上面可以看出,system process是不允许操作sdcard的,有个办法是,可以借助一个运行在user process中的activity helper类完操作sdcard的动作