Android APP自动更新时,跳转到安装界面时出现解析失败

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010886975/article/details/85238755

1、记录一个问题,Android APP自动更新时,跳转到安装界面时出现解析失败,解决办法:
原因是下载文件的权限不正确
因为安装时会跳转到其他应用,其他应用没有改文件的读写权限

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://"+filePath), "application/vnd.android.package-archive");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

修改文件的权限即解决问题

try {
                        //处理安装时,出现解析失败的问题
                        String[] command = {"chmod", "777", new File(PATH + "Xt.apk").getPath()};
                        ProcessBuilder builder = new ProcessBuilder(command);
                        builder.start();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

猜你喜欢

转载自blog.csdn.net/u010886975/article/details/85238755
今日推荐