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
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
.
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
.
You can listen for the android.intent.action.PACKAGE_ADDED
intent.
精彩评论