I want to be alerted, if a headset is plugged in. But the Intent "ACTION_HEADSET_PLUG" is used with the Flag "FLAG_RECEIVER_REGISTERED_ONLY". So I have to run a service or a activity all the time to get the intent? I just want to run a Broadcastreceiver and NO service or activity at all. Is there a workaround for this? Is this even possible? Or can I start a service once, registering and then stopping it?
P.S.: I know when the headset is plugged off with the becoming noisy intent.
Thank you for you answers.
Dianne Hackborn says
So you have to have something running that calls
registerReceiver
. It that stops running and you don't unregister the receiver you get an error.There are components that should be registered when the application is installed (<3.0), or at least when the application has moved from stopped state to started (3.0 & ICS), such as a
ContentProvider
.The provider apparently doesn't have an "end" to it's life cycle that you have to worry (a lot) about.
Simply put, adding a
<provider>
to yourAndroidManifest.xml
:And, for the
ReceiverProvider
:Worth trying perhaps.