【问题标题】:Software Custom Updater, Signed Apk install PARSE ERROR软件自定义更新程序,签名的 Apk 安装 PARSE ERROR
【发布时间】:2015-08-10 20:32:09
【问题描述】:

我正在创建应用程序自定义更新程序,更新时出现 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

我做错了什么?

【问题讨论】:

  • 您是否启用了未知来源的应用安装?
  • 是的,我已经安装了应用程序,只是想制作自定义更新程序
  • 也许这就是您要找的东西? stackoverflow.com/questions/4967669/…

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


【解决方案1】:

找到解决方案..

我忘记添加从外部存储读取的权限,将这一行添加到

AndroidManifest.xml

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

异步任务

@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);
    ......
}

【讨论】:

    猜你喜欢
    • 2023-03-18
    • 2016-04-27
    • 1970-01-01
    • 2016-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多