I want to add custom actions when a Bluetooth headset / earpiece buttons are pressed.
Apparently for this I need to listen to Media Events using mediaSession.setCallback(callback)function. But for that I need to also play some Media as well, right? I dont want to play any sound. Can I ask MediaSession to play nothing and just receive the media events?
My goal is to override the default Bluetooth headset actions. How can I achieve that? Or any listener that can listen to all Bluetooth buttons.
I think you might be looking for BluetoothHeadset.
There you can register for events as well as vendor specific events which I'm sure you can use along with your logcat to find out exactly what events are being issued when certain buttons are being clicked.
Here is an example as well that might help getting you started: https://github.com/devunwired/accessory-samples/blob/master/BluetoothAudioProxy/src/com/example/BluetoothAudioProxy/HeadsetService.java
Related
I'm building a music player and it should be paused when a voice/video chat is taking place. I know I could use an audio focus listener but is there any other way to achieve this?
I've googled a lot but still can't find anything related.
Is there any broadcast event like VOICE/VIDEO_CHAT_START(END) or AUDIO_RECORD_START(END)? Or something like TelephonyManager I could add a listener to?
This question is different from this one. I want to detect events for audio recording instead of playing to be exactly.
I was wondering whether it might be possible to write an app in which the user can go through data by clicking the volume up or down headphone control buttons on their headphones?
Yes, you can do that. You'll need to AudioManager service and extra permission in manifest. You can register callbacks for 'volume up and down' events. See https://developer.android.com/reference/android/media/AudioManager.html
Anyone know if there's a way to control the buttons on both regular and bluetooth headsets?
I want to use the regular answer button to play/pause the current media that I'm playing through the Ti.Media.AudioPlayer.
I've tried to get the Ti.Android.ACTION_MEDIA_BUTTON to work on Android but without any success the BroadCastListener isn't firing when i press button on either a regular headset or a bluetooth headset.
For iOS I have no clue if this is possible to solve.
On iOS if you set the audioSessionCategory to PLAYBACK and the controls on your headset should interact with the music you're playing.
For Android it looks like you'd need a module to expose a broadcast receiver that would pick up the events as explained here. I couldn't find an existing module that does this already.
it's possible to handle the Wired Headset (no bluetooth headset, it is very important) buttons in Android?
For example, if the user press the "Play" button (Receive incoming call), I change a TextView's text (this is a dummy example, not the real mission :) ).
Could somebody post an example code? (if it's possible)
Thanks, IB
Override onKeyDown() in your Activity and watch for the KEYCODE_MEDIA_* family of KeyEvents.
All,
I have searched for an answer to this, but I'm not getting anything exact... It's my first time writing an Android app, so please be gentle :)
I'm pretty bummed about the minimal headset support in Android - unlike e.g. iPhone, it only natively seems to support a single button, so no volume control on headset compatibility. Additionally, if I'm listening to music and a call comes in, the OS pauses the music automatically, but the headset button still functions ONLY as a media button - I can't use it to answer/end the call. If I answer the call via the screen and press the headset button, the music starts again, but the call continues...
I'd like to create a 'middleman' app that can pick up that the headset button has been pressed (via Keyevent.KEYCODE_HEADSETHOOK) and can then determine whether to perform the default ACTION_MEDIA_BUTTON action (toggle play/pause in my chosen media player) or, if there is an incoming call, pause the music and answer the phone (and then, when pressed again, end the call and restart the media player). Perhaps even check for ACTION_MULTIPLE on the headset button to assign different options (ACTION_MEDIA_NEXT, ACTION_MEDIA_PREVIOUS etc.). Perhaps also be able to determine whether different buttons on the headset have been pressed (if the headset is e.g. a fancy iPhone headset) and 'translate' those button presses into the appropriate ACTION_MEDIA_*). This might not be possible if the OS can't tell the difference between different buttons, obviously.
Obviously such an app would have to receive the intent with a high enough priority that it would be able to abort the broadcast before the current media player gets it.
I've been tinkering with creating assorted BroadcastReceiver classes and intent filters etc., but part of the problem is that the bult-in Android emulator that comes with Eclipse doesn't seem to have the ability to simulate a user plugging in the headset and/or subsequently clicking the headset button. Therefore, every time I get somethign that looks promising, I have to put it onto my actual phone and try it out - time-consuming and a hassle.
3 questions then:
Am I missing somethign obvious - is this a real problem and if so, has it already been solved?
If it IS a problem, is it possible to write such a middleman app?
Are there any other Android emulators that can check for headset-related activities?
Thanks,
Rory
i´ve already written exactly this kind of app. Its called like the topic of this thead: Headset Button Controller ;-)
http://www.androidpit.com/en/android/market/apps/app/com.kober.headset/Headset-Button-Controller
Cheers Christoph