admin管理员组文章数量:1585968
最近发现一个问题,当我的apk使用360加固后,在app内检测更新,下载新的apk,安装是华为手机提示“解析包失败”,其他的手机都没问题。
经多方尝试找到解决方法
我设置的是System.exit(0);
想着跟上面说的去掉killProcess
是一样的。结果经过测试,发现真的是这样的呢,在此记录下
附上从服务器下载apk到本地并安装的代码:
private void startDownload(String url) {
File dir = createApkFile();
if (null == dir) {
toast("没有SD卡!");
return;
}
if (null == dialog) {
downLoadDialog = new DownloadProgressDialog(this);
downLoadDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
download.stop();
}
});
}
download.workOn(url, dir.getAbsolutePath());
downLoadDialog.show();
}
private File createApkFile() {
File newFile = null;
try {
File path = new File(getExternalCacheDir(), "apk");
path.mkdirs();
newFile = File.createTempFile("new", ".apk", path);
} catch (Exception e) {
e.printStackTrace();
}
return newFile;
}
void install(){
File file = new File(path);//文件保存在本地的地址
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Uri contentUri = FileProvider.getUriForFile(getApplicationContext(), "包名.provider", file);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(contentUri, "application/vnd.android.package-archive");
} else {
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
}
startActivity(intent);
// System.exit(0);
}
此外还需要在 AndroidManifest中配置:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true"
android:readPermission="company.app.fileprovider.READ"
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
</provider>
版权声明:本文标题:Android 加固后APP内更新安装时华为手机提示解析包失败 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1727974294a1140500.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论