Android使用静默安装时碰见的问题

时间:2023-01-31 15:55:23

升级时碰见的异常

private void installPackage(String appName,final File apk) {
if (!apk.exists()) {
setHasNewVersion(appName,false);
hideProgressDialog();
return;
}
apk.setReadable(true, false);
apk.setExecutable(true, false); //走完installPackage之后就结束了,回调observer内的代码是异步执行了
final PackageManager pm = getPackageManager();
PackageInstallObserver observer = new PackageInstallObserver(appName);
Log.i(TAG, "install the apk begin : "+appName+";;getAbsolutePath="+apk.getAbsolutePath());
pm.installPackage(
Uri.parse("file://" + apk.getAbsolutePath()), observer,
PackageManager.INSTALL_REPLACE_EXISTING, null);
}
private class PackageInstallObserver extends IPackageInstallObserver.Stub {
private String appname;
public PackageInstallObserver(String appName) {
appname=appName;
} public void packageInstalled(final String packageName, int returnCode) {
setHasNewVersion(appname,false);
String appPath = getFilesDir().getAbsolutePath()+"/apps/"+appname+".apk";
File apk = new File(getFilesDir(), appname+".apk"); Log.i(TAG, "install is end and delete "+apk.getAbsoluteFile());
apk.delete();
hideProgressDialog();
if(returnCode==){
installReturnCode=;
}else{
if(returnCode<){
installReturnCode=returnCode;
}else{
installReturnCode=-;
}
}
Log.i(TAG, "installReturnCode "+installReturnCode+"; packageName = "+packageName);
new Thread(){
public void run() {
postUpdateResult(packageName,appname,installReturnCode);//安装成功
};
}.start();
}
}

异常

W/asset ( 1245): Asset path /data/data/com.****.******/files/apps/pjlauncher.apk is neither a directory nor file (type=0).
W/DefContainer( 1245): Failed to parse package
W/ActivityManager( 535): No content provider found for permission revoke: file:///data/data/com.****.***/files/apps/*****.apk
D/dalvikvm( 535): GC_EXPLICIT freed 573K, 24% free 4589K/6028K, paused 2ms+3ms, total 35ms

I/AppUpgradeService( 1227): install is end and delete /data/data/com.****.******/files/apps/*****.apk

查了好半天有说是要添加权限的,有说是要在使用时给apk修改权限的,试了半天都没有效果。

最后修改了apk文件的下载存放路径,结果安装成功。

* 如果apk下载到这个目录/data/data/com.****.******/files/apps
* 会出现No content provider found for permission这个异常
* 如果是这个目录/data/data/com.****.******/files
* 则没有问题

感觉很奇怪我在其他机顶盒上测试的时候,即使是在/data/data/com.****.******/files/apps这个目录也可以顺利安装apk,但是换了一台机顶盒之后就不可以了

可能是不同机顶盒系统有差异吧!

ps:这个功能需要进行系统签名,以及配置android:sharedUserId="android.uid.system"