OK so I have searched and searched, but can’t seem to find a reference that declares that this shouldn’t be possible. Basically what I want to accomplish in my app is to allow the user to register or unregister the broadcast receiver for ACTION_BOOT_COMPLETED.
I try registering it using the code below, but no dice. If I add it to the manifest then I can recieve the events, but with no way to turn it off (from what I can tell). Is there no way to register and unregister a receiver for ACTION_BOOT_COMPLETED?
IntentFilter bootFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
mBootCompleted = new BootBroadcastReceiver();
registerReceiver(mBootCompleted, bootFilter);
Step #1: Put a
<receiver>in the manifest with an<intent-filter>for theBOOT_COMPLETEDbroadcastStep #2: Enable or disable the component as needed from your application, using
PackageManagerandsetComponentEnabledSetting(), based upon whether or not it will be needed for the next bootStep #3: There is no step #3
Of course. In this plane of existence, time proceeds in a linear fashion, always going forward (modulo a TARDIS or appropriately-outfitted DeLorean). By the time you execute the code you show, the boot will have been completed, and there will be no further boot broadcasts until your code is no longer running (because the device has been rebooted).
See the recipe at the top of my answer.