Ajay Singh
Ajay Singh

Reputation: 1621

Android Notification App

I'm currently working on an android application. I have to log any new installed app name whenever the user is installing/downloading a new third party app. How can I get the notification if the user is installing a new app. Thanks in advance.

Java File

public class ApplicationBroadcastService extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent) {
        System.out.print("-------");
    }
}

Manifest

    <receiver android:name=".applicationlog.ApplicationBroadcastService">
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_ADDED"  />
            <action android:name="android.intent.action.PACKAGE_CHANGED" />
            <action android:name="android.intent.action.PACKAGE_INSTALL" />
            <action android:name="android.intent.action.PACKAGE_REMOVED" />
            <action android:name="android.intent.action.PACKAGE_REPLACED" />
        </intent-filter>
     </receiver>

But still I do not enter the onReceive method, when I am installing/uninstalling any app.

Here is the solution:

I did a small change in my Manifest file.

    <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />
            <action android:name="android.intent.action.PACKAGE_ADDED"  />
            <action android:name="android.intent.action.PACKAGE_CHANGED" />
            <action android:name="android.intent.action.PACKAGE_INSTALL" />
            <action android:name="android.intent.action.PACKAGE_REMOVED" />
            <action android:name="android.intent.action.PACKAGE_REPLACED" />
            <data android:scheme="package" />
        </intent-filter>

Now it's working fine.. :) Thanks again @willytate

Upvotes: 15

Views: 13149

Answers (3)

Thibault J
Thibault J

Reputation: 4456

You can listen for the android.intent.action.PACKAGE_ADDED intent.

Upvotes: 3

WarrenFaith
WarrenFaith

Reputation: 57702

Take a look at the intent documentation. You are looking for ACTION_PACKAGE_INSTALL (which seems to be never used, see comments) and ACTION_PACKAGE_REMOVED.

Upvotes: 6

Will Tate
Will Tate

Reputation: 33509

Ajay,

You will need to setup a BroadcastReceiver with an intent filter to receive the following Action: ACTION_PACKAGE_ADDED then from the onReceive() method of the BroadcastReceiver you can launch a Notification.

Upvotes: 8

Related Questions