当我在Manifest.xml中创建和注册接收器时,使用的下面的代码:
<receiver
android:name="com.mycompanh.MyStartReceiver">
<intent-filter>
<action
android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action
android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
那我怎么注销接收器呢?
可以通过PackageManager禁用:
PackageManager pm = this.getPackageManager();
ComponentName receiverName = new ComponentName(this,MyStartReceiver.class);
pm.setComponentEnabledSetting(receiverName, newState, flags);
其中,newState就是COMPONENT_ENABLED_STATE_ENABLED,COMPONENT_ENABLED_STATE_DISABLED,COMPONENT_ENABLED_STATE_DEFAULT 这几个参数;
flags就是DONT_KILL_APP或者0.
具体可以查看setComponentEnabledSetting()方法的注释,说的很清楚.
试试吧,应该可以.