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
Related
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
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.
I want to initiate my activity anytime using Volume up/down hardware button.
I tried in some links but no use.
And also i want to know how to use service for this.
Thanks in advance..
This is not possible on Android. The Volume Buttons can't be monitored or accessed by your app unless it is the current foreground app (i.e. you have an Activity visible and in use on the screen).
An alternative could be to listen for device shake motion and start then.
i need to know in a background task if the user muted the ringer by clicking the volume button when a call is coming in. so there are 2 possible events that i could listen for:
volume button click (onKeyDown) - that would be the preferred method
ringer gets muted
it seems though that this is not possible. anyone has an idea how to accomplish that?
Thx
Simon
There are no broadcasts for exactly what you want, but you can set up a content observer to be notified when settings change (including volume). Please checkout the answer here:
Is there a broadcast action for volume changes?
Use BroadcastReceiver for this with android.media.RINGER_MODE_CHANGED
Also check AudioManager.VIBRATE_SETTING_CHANGED_ACTION ("android.media.VIBRATE_SETTING_CHANGED")
FYI: this is not possible, since the app in the foreground (the Phone app in the moment when the phone is ringing), handles the hardware button click. the event is not passed further.
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