0

I want to receive broadcasts of android installed applications. What would be the procedure ?

Syed
  • 550
  • 1
  • 7
  • 22

1 Answers1

8

You can register Broadcast intent Intent.ACTION_PACKAGE_ADDED ( and/or Intent.ACTION_PACKAGE_REMOVED, Intent.ACTION_PACKAGE_CHANGED if needed).

Code is something like following:

void registerReceiver() {
    IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    filter.addDataScheme("package");
    ...
}

public void onReceive(Context context, Intent intent) {
    String actionStr = intent.getAction();
    if (Intent.ACTION_PACKAGE_ADDED.equals(actionStr)) {
        Uri data = intent.getData();
        String pkgName = data.getEncodedSchemeSpecificPart();
        //handle package adding...
    ...
    }
}
user47
  • 1,080
  • 11
  • 28
RamboWang
  • 272
  • 3
  • 3