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>

本文标签: 华为提示手机androidapp