When users double click the play/pause button on their headsets quickly, I have code to detect that and skip to the next song automatically. Unfortunately it seems like when using the RemoteControlClient, it uses the same PLAY_PAUSE event. If you accidently click twice on the lockscreen pause (or more commonly, accidently double click on the Android Wear display to try to get it to respond), it then skips to the next song. I only want this to happen on Bluetooth headsets though. Is there a way to differentiate between the two?
I would prefer you to go through https://developer.android.com/sdk/api_diff/19/changes.html
Sure, this will help you a lot.
Related
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'm writing an Android music player, and is stuck on audio focus issue.
It seems like audio focus mainly affects media button receiving, but after reading the document I have no idea about when to gain and give up focus.
My music app will run in background, and need to detect play/pause button every time. That is, even when my app is not running, a user should be able to press headset's play button and start music.
It seems I should never give up audio focus, so why should I implement it?
Does anyone know practically how audio focus should be used? Thank you!
It seems like audio focus mainly affects media button receiving, but
after reading the document I have no idea about when to gain and give
up focus.
They both are separate functionalities, and thus have separate listeners. You may have audio focus taken away from you but you may still choose to respond to play pause hardware keys
That is, even when my app is not running, a user should be able to
press headset's play button and start music.
I am assuming that you meant by the above line is that you are still playing music but not showing an activity. To keep listening to hardware button press, dont unregister your media button receiver(dont call audioManager.unregisterMediaButtonEventReceiver(receiver) yet).
It seems I should never give up audio focus, so why should I implement
it?
you dont give up the focus , it gets taken from you. To handle that gracefully you have AudioFocus listener. For ex, consider an incoming phone call. Would you still like to continue playing your music?
When using Slacker Radio on my android phone I am able to skip to the next song when the display is off by long pressing the volume button.
What part of the API should I be looking at to implement such a feature for my app?
I think you might find what your looking for from this post. You just need to listen for that specific key event. You might want to look into a WakeLock to keep your program active when the display is turned off.
Alright, so I'm writing an app to make an external headset perform certain functions. I'm trying to replicate functionality similar to this guy:
https://market.android.com/details?id=com.kober.headset
The list of things it can make the headset button click do is: play/pause, previous track, redial last phone #, launch specified app, etc. I don't know how to do this stuff though! Sort of lost with how to get started here. I'm also kind of confused how the overall program flow should work.
Right now I can register button clicks via a broastcast receiver and correctly and pass that number (single/double/triple click) to a service to run in the background. I'm using a background service so the user doesn't need to be in the app to use the functionality.
Am I on the right track? How do I go about making clicks play/pause music, next/previous track, etc? Are there certain intents I should be using?
Cheers.
Am I on the right track?
Be sure to stop your service when it is no longer needed (e.g., after you have determined the clicks and performed the operation). Otherwise, I see no problems there.
How do I go about making clicks play/pause music, next/previous track, etc?
First, write a music player app. There are no documented and supported APIs to "play/pause music, next/previous track, etc" for most of the several thousand music players out there.
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