android 6.0 更新apk失败解决


一.清单文件内添加如下;

 
            
        

二.res内创建XML文件夹添加一个rc_file_path.xml文件如下;


    


三.mainactivity内代码如下;

 private void installApk() {
        String fileStoreDir = this.getExternalCacheDir().getPath();
        String fileName = "test" + "001" + ".apk";
        File file = new File(fileStoreDir, fileName);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        if (Build.VERSION.SDK_INT >= N) {
            Uri apkUri = FileProvider.getUriForFile(MainActivity.this, "包名.fileProvider", file);
            intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        } else {
//                            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
        }
        startActivity(intent);
    }


你可能感兴趣的:(android 6.0 更新apk失败解决)