本APP
- 权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
- 实例化File类
try {
File installation = new File("文件路径", "文件名");
if(!installation.exists()) {
return;
}
....
} catch (Exception e) {
Log.d(TAG, "overrideInstallation: " + e.getMessage());
}
有File对象即可通FileOutputStream或FileReader操作文件。
别APP
问题
open failed EACCES (permission denied)
即使可实例化File、文件exists为true、有权限,仍上错。
原因
每app都有自己linux user id
,不同user id
进程间不许共享文件。
解决
可于AndroidManifest声明同sharedUserId
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx.xxx"
android:sharedUserId="xxx">
</manifest>
sharedUserId
- 获同
sharedUserId
之Context - 共享数据
独立开发者很少需关心,但一些公司产品群常用同sharedUserId,这样app间可数据共享并可做一些其它操作,如保活、监控。