软件自定义更新程序,已签名Apk安装PARSE ERROR

时间:2015-08-10 20:32:09

标签: android android-intent android-activity android-file start-activity

我正在创建应用程序自定义更新程序,在更新时出现Parse错误。

我使用AsyncTask下载签名的apk

output = new FileOutputStream(context.getFilesDir()+"/update.apk");

下载成功完成,然后我尝试像这样运行apk:

File file = new File("file://"+context.getFilesDir(), "update.apk");
file.setReadable(true, false);
Intent promptInstall = new Intent(Intent.ACTION_VIEW)
    .setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");

promptInstall.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
promptInstall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(promptInstall);

应用程序开始更新,但后来解决了我的问题,

Parse Error: An error occurred while parsing the package

我做错了什么?

1 个答案:

答案 0 :(得分:0)

找到解决方案..

我忘了添加从外部存储中读取的权限,将此行添加到

<强>的AndroidManifest.xml

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />    

<强>的AsyncTask

@Override
protected String doInBackground (String...sUrl){
    ......
    File sd = Environment.getExternalStorageDirectory();
    File outputFile = new File(sd, "/download/update.apk");
    output = new FileOutputStream(outputFile);
    ......
}


@Override
protected void onPostExecute(String result) {
    ......
    File sd = Environment.getExternalStorageDirectory();
    File inputFile = new File(sd, "/download/update.apk");

    Intent promptInstall = new Intent(Intent.ACTION_VIEW);
    promptInstall.setDataAndType(Uri.fromFile(inputFile), "application/vnd.android.package-archive");

    promptInstall.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    promptInstall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(promptInstall);
    ......
}