I want to write a small app that changes the volume of STREAM_VOICE_CALL depending on the state of the headset. Therefor I need to capture every ACTION_HEADSET_PLUG. This broadcast can not be captured by a receiver declared in manifest because FLAG_RECEIVER_REGISTERED_ONLY is set, like described here: http://www.mail-archive.com/[email protected]/msg24461.html
The only way to capture every of this broadcasts seems to be a service that is started on boot and then uses registerReceiver() in his onCreate(). Now I've got some questions: I could return START_STICKY at onStartCommand() to make the service kind of everlasting and register an inner class in the service itself as the receiver. This doesn't appear to be best practice, like mentioned here: http://www.androidguys.com/2009/09/09/diamonds-are-forever-services-are-not/ Is there any other way to implement a receiver for ACTION_HEADSET_PLUG, without wasting resources by an everlasting service? Could I just register the receiver without using unregisterReceiver in the onDestroy of the service and without the START_STICKY? If the service gets killed, will the broadcast get processed? I believe not :/ [If the device is in sleep mode, will the broadcast be send at any time or will it be canceled? It doesn't mention to me if it's not send till the user wakes up the device, as long as the broadcast is send then. I believe it is send as soon as the device wakes up, and that would be okay] Here is a scheme of how the app should work: 1). Headset gets plugged in. The app saves the current volume as the volume the user wants when no headsets are plugged in. 2). The user makes a call and adjusts the volume. 3). The headset is pulled. The app saves the current volume as the volume the user wants when a headset is plugged in and adjusts the volume to the value saved in 1). 4). The user makes a call and adjusts the volume. 5). Headset gets plugged in. The app saves the current volume as the volume the user wants when no headsets are plugged in and adjusts the volume to the value saved in 3). The effect is that the user always has the volume he wanted the last time he made a call when the headphone-state was like it is now. This would be a big benefit for my ears, since I use the full volume when making a call without the headset, which is way to loud when making a call with the headset. By the way it would be great if there was a broadcast for STREAM_VOLUME_CHANGED ;) Thank you for your answers! Greetings from Germany (I hope my english is not to bad ;)) -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

