2

How can I know if an app has been installed successfully in android? I am using the following method to install apk files.

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
startActivity(intent);
Dmitry Evseev
  • 11,533
  • 3
  • 34
  • 48
althaf_tvm
  • 773
  • 3
  • 15
  • 28

2 Answers2

3

You can query the list of installed packages and look for the one you just installed:

List pkgAppsList = context.getPackageManager().getInstalledPackages();

http://developer.android.com/reference/android/content/pm/PackageManager.html#getInstalledPackages%28int%29

Aleadam
  • 40,203
  • 9
  • 86
  • 108
  • The simplest way I can think of is to set a timer and query the PackageManager every 60 seconds, until you find the package, or until you decide it's not installed successfully (i.e., after 5 tries, since 5 minutes should be plenty for any app to install). I could not find if there is any info whatsoever about failed installations, so I would go for a simple "is it there?" approach. – Aleadam Apr 11 '11 at 12:04
3
private boolean isAppInstalled(String uri) {
PackageManager pm = getPackageManager();
boolean installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
installed = true;
} catch (PackageManager.NameNotFoundException e) {
installed = false;
}
return installed;
}

Just call the method by passing the package name of the application you need to check.

if(isAppInstalled("com.yourpackage.package")){
//app installed
}
else{
//app not installed
}