有没有办法在APK安装失败时收到通知?
我正在写一个应用程序。 在应用程序中,我以编程方式下载 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:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不能 100% 确定这种方法是否适用于所有可能的情况,但我一直在测试并且至少对我有用。
我没有找到有关检测 Android 中安装错误的信息,因此我尝试先发制人地检测 apk 文件是否已损坏。
根据此链接,apk只是带有 dalvik 代码的 jar 文件。因此,您可以使用 zip 解压缩来检测文件是否已损坏以及解析包时是否存在任何问题。
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.