Android common user id and file read / write

For several days I suffered from one problem. I am currently running the "Settings" source code on Android2.2.

In AdroidMenifest.xml we can see:

android:sharedUserId="android.uid.system" 

With this, you can access many permissions for actions in the settings. But with this statement, the sd card cannot be read / write, I tried to read the files in the directory

 File f = new File("/mnt/sdcard/"+filename); 

or

 File f = new File("/sdcard/"+filename); 

But they all do not work, I got an exception saying that the file does not exist (I already put the file there).

If I remove android:sharedUserId="android.uid.system" , I can access the file successfully. However, I need android:sharedUserId="android.uid.system" for other actions to work well.

Has anyone encountered the same problem, and have you resolved this? Thanks!

+4
source share
1 answer

The system user cannot access the SD card, because if the SD card is unmounted, it may be necessary to destroy any processes that have files on it, and we do not want the system processes to be killed. If you want to access the SD card, you do not need to use the system common user ID.

+9
source

Source: https://habr.com/ru/post/1347504/


All Articles