Android的共享用户ID和读/写文件 [英] android shared user id and reading/writing a file

查看:128
本文介绍了Android的共享用户ID和读/写文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直受着一个问题了好几天。 目前,我在设置中对Android2.2的源$ C ​​$ C正在运行。

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

在AdroidMenifest.xml,我们可以看到:

In AdroidMenifest.xml, we can see:

android:sharedUserId="android.uid.system"

通过这一点,许多权限可以访问在设置的活动。 但这种说法,SD卡不能进行读/写访问,我试图读取目录中的文件

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);

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).

如果我删除安卓sharedUserId =android.uid.system,那么我就可以成功地访问该文件。不过,我需要的安卓sharedUserId =android.uid.system 使其他活动运行良好。

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!

推荐答案

该系统用户无法访问SD卡,因为如果SD卡获取卸载它可能需要杀死有它,我们不打开文件的任何进程'吨要系统进程被杀死这样。如果您要访问的SD卡,你需要不使用系统共享的用户ID。

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.

这篇关于Android的共享用户ID和读/写文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆