How to detect new apps in an Android device

送分小仙女□ 提交于 2019-12-03 08:51:35

You can register a BroadcastReceiver using Intent.ACTION_PACKAGE_ADDED (and also Intent.ACTION_PACKAGE_REMOVED and/or Intent.ACTION_PACKAGE_CHANGED if necessary). For instance,

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. */
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!