Is PackageManager.getComponentEnabledSettings() persistent between cold starts?

末鹿安然 提交于 2020-01-01 03:35:27

问题


If I use the code below to disable a static BroadcastReceiver defined in AndroidManifest.xml, will it be re-enabled after a reboot? It doesn't appear to be but the docs don't say whether it should.

final ComponentName compName =
        new ComponentName(context,
        MyBroadcastReceiver.class);

context.getPackageManager().setComponentEnabledSetting(
        compName,
        PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
        PackageManager.DONT_KILL_APP);

Thanks in advance...


回答1:


Is PackageManager.getComponentEnabledSettings() persistent between cold starts?

Yes. It will be reset on an application uninstall/reinstall. It will be reset if you reset it yourself with setComponentEnabledSetting(). It'll be reset if something with superuser privileges resets it (e.g., the device might have some manager app for controlling ACTION_BOOT_COMPLETED). And I'm not sure what happens on an app upgrade, as I haven't tried that scenario. Otherwise, it should stay persistent.

If I use the code below to disable a static BroadcastReceiver defined in AndroidManifest.xml, will it be re-enabled after a reboot?

No.



来源:https://stackoverflow.com/questions/22949754/is-packagemanager-getcomponentenabledsettings-persistent-between-cold-starts

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