Can he not access the SD card after installing "android.uid.system" in my application?

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.

+4
source share
5 answers

Read the following: link1

and link2

+5
source

Use Environment.getExternalStorageDirectory().getAbsolutePath() to get the path, NOT "/mnt/sdcard"

0
source

Usage: File share = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),"test.txt");

This will not work: File share = new File("/mnt/sdcard", "test.txt");

0
source

You can see the Android source code: frameworks \ base \ core \ java \ android \ os \ Environment.java, it has a function:

 private static void throwIfSystem() { if (Process.myUid() == Process.SYSTEM_UID) { Log.wtf(TAG, "Static storage paths aren't available from AID_SYSTEM", new Throwable()); } } 

This function will be called getExternalStorageDirectory() , so an application with a uid system will not be able to access sdcard unless you hack aosp.

0
source

android.uid.system will make your application binding system, but sdcard will also be monitored by the system, and then if your application removes it, it will be able to access the SD card. it seems

delete this line in the xml: android: sharedUserId = "android.uid.system" ystem file

-1
source

All Articles