Ale*_*s95 3 android broadcastreceiver android-package-managers contentobserver
我想检测用户何时安装或删除应用程序,但我没有找到BroadcastReceiver这样做.
在我的应用程序中,我获得了有关已安装的应用程序的信息PackageManager,但我不想定期扫描应用程序.有没有BroadcastReceiver这样做?还是任何ContentObserver?是否可以获得已安装或删除应用程序的通知?
您可以注册BroadcastReceiver使用Intent.ACTION_PACKAGE_ADDED(以及 Intent.ACTION_PACKAGE_REMOVED和/或Intent.ACTION_PACKAGE_CHANGED必要时).例如,
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_name");
}
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action.equals(Intent.ACTION_PACKAGE_ADDED)) {
Uri data = intent.getData();
String pkgName = data.getEncodedSchemeSpecificPart();
}
/* etc. */
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3277 次 |
| 最近记录: |