我最初的问题基本上与此类似:
Clearing and setting the default home application
我很满意地回答了这个问题,但是我在答案中难以理解的是你如何在java代码中启用然后禁用清单中的组件?
解决方法
通过使用包管理器,您可以启用或禁用在清单文件中声明的组件
禁用组件有两个标志PackageManager.COMPONENT_ENABLED_STATE_DISABLED,启用组件有PackageManager.COMPONENT_ENABLED_STATE_ENABLED标志.
禁用组件有两个标志PackageManager.COMPONENT_ENABLED_STATE_DISABLED,启用组件有PackageManager.COMPONENT_ENABLED_STATE_ENABLED标志.
PackageManager pm = getApplicationContext().getPackageManager(); ComponentName componentName = new ComponentName("com.app",".broadcast_receivers.OnNetworkChangedReceiver"); pm.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP);
Android清单:
<receiver android:name=".broadcast_receivers.OnNetworkChangedReceiver" android:enabled="true"> <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/> </intent-filter> </receiver>