How to catch or receive android os ' broadcasts' of installed applications?
I want to r开发者_JAVA技巧eceive broadcasts of android installed applications. What would be the procedure ?
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...
...
}
}
精彩评论