Issue
I update my app using a local downloaded .apk, via DownloadManager, using this code:
val installIntent = Intent(Intent.ACTION_VIEW)
installIntent.setDataAndType(localUri, "application/vnd.android.package-archive")
installIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
this.startActivity(installIntent)
Although most of the time it works, sometimes, only some of the users get the "There was a problem parsing the package error" popup.
I'm interested if there is any callback that we can get in our app, whenever this happens, or user press 'OK' in the popoup . I found here for instance, a callback that checks if the package exists (meaning that it was installed) but I'm more interested for updates, in this case I already know that the app was previously installed.
Is there a callback (maybe startActivityForResults) for this specific intent, so we know that it was successfully installed or it failed?
Solution
ACTION_VIEW is not designed to return a result. On Android 5.0 and higher, PackageInstaller gives you a direct API for installing apps, where you can provide a callback (in the form of an IntentSender) to find out about how the installation proceeds.
This sample project shows the basics of using PackageInstaller, and you should be able to find open source apps that use it in a more sophisticated fashion. For example, the F-Droid client probably uses PackageInstaller.
Answered By - CommonsWare
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.