【问题标题】:Is there a way to be notified when APK fails to being installed?有没有办法在APK安装失败时得到通知?
【发布时间】:2011-12-01 09:06:38
【问题描述】:

我正在编写一个应用程序。 在应用程序中,我以编程方式下载 APK 并启动 启动 APK 安装的意图。

Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "app.apk")),
                "application/vnd.android.package-archive");
        startActivity(intent);

一切正常。

但是当我尝试启动安装损坏的 APK 时 出现一个对话框:

我希望在安装 APK 出现问题(APK 损坏、空间不足等...)时收到通知。

那么,有没有办法(事件或其他东西)得到通知,所以我可以替换 带有我自己的对话框的“解析错误”默认对话框?

谢谢!

【问题讨论】:

    标签: android installation apk


    【解决方案1】:

    我不能 100% 确定这种方法是否适用于所有潜在情况,但我一直在测试并且至少对我有用。

    我还没有找到有关在 Android 中检测安装错误的信息,因此我尝试先发制人地检测 apk 文件是否已损坏。

    根据link,apks 只是带有 dalvik 代码的 jarfile。所以你可以使用一个zip解压来检测文件是否已经损坏以及解析包的任何问题。

    boolean corruptedApkFile = false;
    try {
         new JarFile(updateFileFullPath); //Detect if the file have been corrupted
    } catch (Exception ex) {
         corruptedApkFile = true;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-21
      • 2016-04-21
      • 2012-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多