Android APP自動更新時,跳轉到安裝界面時出現解析失敗

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();
                    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章