Android 加固后APP内更新安装时华为手机提示解析包失败

最近发现一个问题,当我的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="com.company.app.fileprovider.READ"

            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths"/>
        </provider>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嘟嘟嘟~~~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值