Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android shared user id and reading/writing a file

Tags:

file

android

I have been sufferring in one problem for several days. Currently I'm running in the source code of "Settings" on Android2.2.

In AdroidMenifest.xml, we can see:

android:sharedUserId="android.uid.system"

With this, many permissions can be accessed for the activities in Settings. But with this statement, the sd card can't be accessed for Read/Write, I have tried to read files in directory

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

or

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

But all of them don't work, I got an exception telling me that the file didn't exist (I have already put the file there).

If I delete android:sharedUserId="android.uid.system", then I can access the file successfully . However, I need the android:sharedUserId="android.uid.system" to make the other activities run well.

Does anybody happened to meet the same problem, and have you solved it? Thanks!

like image 920
Mustafa İrer Avatar asked Jan 21 '23 01:01

Mustafa İrer


1 Answers

The system user can not access the SD card, because if the SD card gets unmounted it may need to kill any processes that have files open on it and we don't want system processes being killed like that. If you want to access the SD card, you need to not use the system shared user ID.

like image 117
hackbod Avatar answered Jan 28 '23 05:01

hackbod