捆绑安装assert文件下的apk时模拟器提示错误:there is aproblem parsing the package , 换成真机也提示同样的错误:解析包时出现问题
自己是通过将assert下的apk文件另存到缓存文件夹中(data/data/<packname>/cache)然后再安装, 但是此目录下的文件是默认只有此应用可以读写,所以想让apk安装器读这里 必须重新设置权限。
在下面安装代码之前设置权限就可以了
设置权限:
try{ String command = "chmod 777 "+cachePath; Runtime runtime = Runtime.getRuntime(); runtime.exec(command); }catch(IOException e) { e.printStackTrace(); }
然后安装:
Intent intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(Uri.parse("file://" + cachePath), "application/vnd.android.package-archive"); startActivity(intent);