Listen for app installed / upgraded broadcast message in Android

I hope Intent.ACTION_PACKAGE_ADDED is the answer but it's wrong (ACTION_PACKAGE_ADDED: A new application package has been installed on the device. The data contains the name of the package. Note that the newly installed package does not receive this broadcast.) while ACTION_PACKAGE_INSTALL is deprecated.

Can anyone tell me a better way? Any help is welcome.

101k 96 96 gold badges 433 433 silver badges 930 930 bronze badges asked Apr 24, 2012 at 11:42 6,864 9 9 gold badges 46 46 silver badges 78 78 bronze badges why is ACTION_PACKAGE_ADDED wrong? Commented Apr 24, 2012 at 11:50 Because "Note that the newly installed package does not receive this broadcast"; Commented Apr 24, 2012 at 11:52 You don't get the message yourself if you was just installed. That's not what you want I guess. Commented Apr 24, 2012 at 11:55

zapi is correct -- you cannot use ACTION_PACKAGE_ADDED to find out about your own app being installed.

Commented Apr 24, 2012 at 12:12

AFAIK, This is quite difficult to get broadcast at the time of installation. But I have some trick may be this will help you. If you set some other broadcast receiver which can frequently calls in the application like Battery status, Phone state, wifi-state changed and some more so that there is possibility that you can get at least one of the broadcast receive so you can work at the time.

Commented May 3, 2012 at 19:36

5 Answers 5

If you are installing an application A, all other applications on the device will get the Intent that application A is the newly installed application but not A itself as it doesn't seem of any use. Now A will get broadcasts if other apps are later installed or changed.

If you want to find out at when your app was installed or some other app's the last install or update time, you can always use PackageManager :

PackageManager pm = context.getPackageManager(); ApplicationInfo appInfo = pm.getApplicationInfo("app.package.name", 0); String appFile = appInfo.sourceDir; long installed = new File(appFile).lastModified(); 

here app.package.name is the package name of the app you want to find out the install time. If you want to use it for your app, pass in your app's package name.