我在安装Android内部缓存中保存的APK时遇到了问题。使用context.getExternalCacheDir().将文件保存在外部存储或外部缓存中没有问题
但是,如果我尝试使用context.getCacheDir(),,日志将返回
/data/data/com.my.package/cache/update.apk:打开失败: EACCES (权限拒绝)
File file = context.getCacheDir();
File outputFile = new File(file, "update.apk");
if(outputFile.exists()){
outputFile.delete();
}
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
Intent intent = new Intent(Intent.ACTION_VIEW);
//SAVE IN CACHE
intent.setDataAndType(Uri.fromFile(outputFile), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // without this flag android returned a intent error!
context.startActivity(intent);看起来内部缓存不允许正确读取APK。
事实是,如果文件保存在外部存储或外部缓存中,那么APK将对用户可用,我不想这样做。
在内部缓存中保存文件可以是什么?
谢谢
发布于 2012-09-24 19:09:13
看起来内部缓存不允许正确读取APK。
这是因为安装程序没有权利读取您的文件。
事实是,如果文件保存在外部存储或外部缓存中,那么APK将对用户可用,我不想这样做。
然后不要将它安装在用户的设备上。任何用户都可以在安装后的任何时间从设备上复制任何APK,因此防止用户访问APK的唯一方法是首先不要在设备上使用APK。
在内部缓存中保存文件可以是什么?
可能什么都没有。如果切换到openFileOutput(),您可以看到MODE_WORLD_READABLE是否足以让安装程序继续工作。同样,这不会阻止用户访问APK文件。
发布于 2012-09-24 19:07:40
尝试查看chmod命令以获得内部文件夹的读\写权限.至于linux,看上去.
chmod 777 /data/data/*** or chmod 644 /data/data/***https://stackoverflow.com/questions/12571207
复制相似问题