0

How can I know from packageManager if a package is still in the installation process (already started, but not yet finished installing)? The installation is using below source code:

Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
File file = new File(pathToAPK);
        intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
        startActivity(intent);
user1012283
  • 343
  • 2
  • 13
  • WHY do you want to know that? – Nguyễn Hoài Nam Jan 19 '15 at 04:13
  • @NguyễnHoàiNam: Because I want to know if the installation is still happening or not, so I can decide whether I should disable or enable my installation button. The installer dialog will just only show "Cancel" and "Install" options, but I can't know whether the user actually press the "Cancel" or "Install' or even just touch outside of the install dialog screen and close the installation window. thanks. – user1012283 Jan 19 '15 at 05:29
  • I think I got your idea. I'm thinking of startActivityForResult, but could not check if it's a good solution. Hope the following links help you: http://stackoverflow.com/questions/6157567/install-apk-programmatically-return-value http://stackoverflow.com/questions/12403535/how-to-detect-if-user-clicked-done-or-open-after-application-in-android-has-been – Nguyễn Hoài Nam Jan 19 '15 at 07:18
  • @NguyễnHoàiNam: Hi thanks for the links. I have tried that too, but the activityResult will get called even when the installer dialog just opened. So I think the only thing I can think of is using the PackageManager, but I don't know which one to use in PackageManager to get the status of the installation (I mean the app is still got installed, but not yet finished). thanks. – user1012283 Jan 19 '15 at 07:27
  • How about registering a broadcast receiver to listen to those Intent actions related to ACTION_PACKAGE (http://developer.android.com/reference/android/content/Intent.html), then set the response activity for each type. An example/question from SO: http://stackoverflow.com/questions/14350460/android-broadcastreceiver-on-application-install-uninstall // that's all I can find. If it doesn't help, I would like to wait for better response! – Nguyễn Hoài Nam Jan 19 '15 at 08:33
  • @NguyễnHoàiNam: Thanks for the links. I have made the receiver with filter almost all kind of action, but only one is returned, which is if the package has been finished installed (ACTION_PACKAGE_ADDED). – user1012283 Jan 19 '15 at 08:44

0 Answers0