koder
koder

Reputation: 554

BroadcastReceiver on new app installs

I want to receive a notification when a new application is installed.

IntentFilter newAppFilter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
newAppFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
newAppFilter.addAction(Intent.ACTION_PACKAGE_INSTALL);
newAppFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
getApplicationContext().registerReceiver(newAppReceiver, newAppFilter);


public static BroadcastReceiver newAppReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {     
            Log.e("Broadcast","Received");
       }
};

But I am not able to get any log. Anyone can help me?

Upvotes: 3

Views: 1898

Answers (2)

Sergey Glotov
Sergey Glotov

Reputation: 20356

Try to add data scheme to your IntentFilter.

newAppFilter.addDataScheme("package");

Reference: IntentFilter.addDataScheme() documentation

If no schemes are included, then an Intent will match only if it includes no data.

Upvotes: 10

gsysko
gsysko

Reputation: 988

If anyone runs across this, the intent documentation now says:
ACTION_PACKAGE_INSTALL - This constant is deprecated. This constant has never been used.

Upvotes: 2

Related Questions