有没有办法在APK安装失败时收到通知?

发布于 2024-12-18 23:22:42 字数 591 浏览 2 评论 0原文

我正在写一个应用程序。 在应用程序中,我以编程方式下载 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 损坏、空间不足等)时收到通知。 ..)。

那么,有没有一种方法(事件或其他东西)可以收到通知,这样我就可以替换 “解析错误”默认对话框与我自己的对话框?

谢谢!

Im writing an application.
In the application i download programatically an APK and start an
intent which launches the APK installtion.

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);

it all works well.

but when i try, for example, to launch an installation of a coruupted APK
There's a dialog which comes up:
enter image description here

I want to be notified when there's a problem installing the APK (corrupted APK, not enough space, etc...).

So , is there a way (Event or something) to be notified about that, so I can replace
the "Parse error" defalt dialog with my own dialog?

thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若无相欠,怎会相见 2024-12-25 23:22:42

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

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

根据此链接,apk只是带有 dalvik 代码的 jar 文件。因此,您可以使用 zip 解压缩来检测文件是否已损坏以及解析包时是否存在任何问题。

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

I am not 100% sure if this method will work in all the potential situations but I have been testing and at least works for me.

I have not found information about detecting installation errors in Android so I try to preemptively detect if the apk file is corrupted.

According to this link, apks are simply jarfiles with dalvik codes. So you can use a zip decompression to detect the file have been corrupted and any problem parsing the package.

boolean corruptedApkFile = false;
try {
     new JarFile(updateFileFullPath); //Detect if the file have been corrupted
} catch (Exception ex) {
     corruptedApkFile = true;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文