[英]Android - Install APK via intent - react to failure
I am installing an APK via the following intent: 我通过以下意图安装APK:
val apkUri = Uri.fromFile(apkFile)
val intent = Intent(Intent.ACTION_VIEW)
intent.setDataAndType(apkUri, "application/vnd.android.package-archive")
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
context.startActivity(intent)
I know that I can retrieve the PACKAGE_ADDED broadcast and then react in case the APK was installed. 我知道我可以检索PACKAGE_ADDED广播,然后在安装APK的情况下做出反应。 However, how can I react if the installation failed?
但是,如果安装失败怎么办? Eg if the APK was not parsed correctly (eg if its for a different architecture) or simply if the user clicks "CANCEL" on the request?
例如,是否未正确解析APK(例如,是否针对不同的体系结构),或者仅是用户在请求上单击“取消”?
I also tried startActivityForResult
and the corresponding onActivityForResult
functions, but that seems to be independent on the user action and is immediately triggered when the intent was fired. 我还尝试了
startActivityForResult
和相应的onActivityForResult
函数,但这似乎独立于用户操作,并且在触发意图时立即被触发。
The answer is that there is no standard way of doing it. 答案是没有标准的方法可以做到。 If you look at the source of the package manager service you will see that there is no event broadcasted for when it is not successful.
如果查看包管理器服务的源,您将看到不成功时不会广播任何事件。
You could in theory do a few things... 从理论上讲,您可以做一些事情...
These options won't be perfect and might not work on all implementations but might lead you in the right direction. 这些选项不是完美的,可能无法在所有实现上都起作用,但可能会引导您朝正确的方向发展。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.