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);
publ开发者_如何学Cic 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?
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.
If anyone runs across this, the intent documentation now says:
ACTION_PACKAGE_INSTALL - This constant is deprecated. This constant has never been used.
精彩评论