This is a strange problem. My application can access the SD card successfully if I have not installed android.uid.system for it. But after installing android.uid.system on it, my application cannot access the SD card. An exception occurs at this time: 07-13 09:11:24.999: INFO/System.out(9986): create file happen exception--->java.io.IOException: Permission denied . I verify that I am writing the correct resolution in the right place:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />.
Because use forceStopPackage in my application, I need to add android.uid.system to the manifest. And I wrote LOCAL_CERTIFICATE := platform in the make file. Who can explain this strange problem. After installing android.uid.system my application belongs to the system process, which should have more options for accessing the SD card. This is my idea. Below is my code:
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() ); } }
And my application running on the emulator and its target version is 2.3. Thank you very much.
source share