【发布时间】:2011-07-13 12:38:38
【问题描述】:
这是一个奇怪的问题。如果我没有设置android.uid.system,我的应用程序可以成功访问 SD 卡。但是在设置android.uid.system 之后,我的应用程序无法访问sdcard。这时出现异常:07-13 09:11:24.999: INFO/System.out(9986): create file happen exception--->java.io.IOException: Permission denied。我检查我在正确的地方写了正确的权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />.
因为在我的应用程序中使用了forceStopPackage,所以我需要将android.uid.system 添加到清单中。我在make文件中写了LOCAL_CERTIFICATE := platform。谁能解释这个奇怪的问题。设置android.uid.system后,我的应用程序属于系统进程,应该有更多的权力来访问sdcard。这是我的想法。以下是我的代码:
public void setPackage(String dir){
System.out.println( "setPackage dir=="+dir );
File share=new File("/mnt/sdcard","test.txt");
if(!share.exists()){
try{
share.createNewFile();
}catch(Exception e){
System.out.println( "creat file happen exception--->" +e.toString() );
}
}
try{
if(share!=null){
System.out.println( "create file is not null" );
FileOutputStream fops=new FileOutputStream(share);
fops.write(dir.getBytes());
fops.flush();
fops.close();
}
}catch(Exception e){
System.out.println( "write Exception-->" +e.toString() );
}
}
我的应用程序在模拟器上运行,他的目标版本是 2.3。非常感谢。
【问题讨论】:
标签: android android-emulator android-manifest