15

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

Aki K
  • 1,222
  • 1
  • 27
  • 49
Ajay Singh
  • 1,611
  • 3
  • 22
  • 29
  • Is there any launcher activity in your code?Will you please share your whole code because I tried your code but its not working for me. – Nitish Patel Jan 28 '14 at 06:33
  • How to trigger onReceive if app is not running in background.if app is running onReceive methode for Package_ADDED and REMOVED working.But i need to trigger Even app is not running please help me – Harsha Apr 15 '20 at 10:29

3 Answers3

8

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.

Will Tate
  • 33,439
  • 9
  • 77
  • 71
  • 1
    @willylate, Please see my code. i am still not get into onReceive method. correct me if i have done something wrong. – Ajay Singh Mar 31 '11 at 12:32
  • well, i know to receive `PACKAGE_REMOVED` you need the permission `BROADCAST_PACKAGE_REMOVED`. Try just setting the receiver line to `` that usually works fo rme. – Will Tate Mar 31 '11 at 12:44
  • 1
    How could i get the name or the info about the last installed app... Thanks – Vervatovskis May 04 '12 at 08:50
  • 1
    You could try using the `EXTRA_UID` value that is passed in with the data during this intent. It should give you the ID value of the last app installed. Use this information to retrieve more information about the app from `PackageManager`. This is just an educated guess though... – Will Tate May 04 '12 at 14:07
  • @WilliamTate Is there any launcher activity in your code?Will you please share your whole code because I tried your code but its not working for me – Nitish Patel Jan 28 '14 at 06:43
  • @nitishpatel Full source code can be found here: https://github.com/willtate/Will-Deux keep in mind this question is almost 2 years old (so is my source) and Android has progressed by leaps and bounds since then! good luck. – Will Tate Jan 28 '14 at 14:31
6

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.

WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
  • 3
    nope, try to implement what willytate mentioned. Nobody will write code for you. If you stuck, ask a new question (and don't ask for code there, present what you have...) – WarrenFaith Mar 31 '11 at 11:37
  • Thanks @WarrenFaith, your answer was not very clear to me.that's why i ask for some clue. anyway thanks for your response. – Ajay Singh Mar 31 '11 at 11:48
  • The docs say ACTION_PACKAGE_INSTALL was never used. http://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_INSTALL – gonzobrains May 28 '13 at 20:11
  • thanks for saying, for the time this was written, it wasn't mentioned in the documentation... – WarrenFaith May 28 '13 at 20:40
3

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

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
Thibault J
  • 4,336
  • 33
  • 44