I have an Camera Shutter for my Android phone.
It is an bluetooth device which has one button and connect as a bluetooth keyboard to the phone. If button get pressed it sends keycode.enter and volume up.
My question is is it possible to intercept its message in an background service?
So far I read the keyevent is not available in background.
But can I intercept the Bluetooth changes or something else?
Some Ideas?
I would like to give a notification on press of the button. When its running as a background service.
Thanks and best regards
As you already know background services cannot listen for KeyEvents View.OnKeyListener
But you can handle BluetoothSocket events as you would with a standard Socket
I think the Android Bluetooth Overview page is a good starting point
Good luck
Related
I'm trying to develop an app that recognizes when a paired bluetooth keyboard's key is pressed and wakes up the app with certain action. The bluetooth device in particular is the Selfie Remote Shutter (this one, no ads intended: http://www.ebay.es/itm/like/361219097614) and it's recognized by the device as a bluetooth keyboard. It sends two different events which the SO in Android identifies as key volume up pressed and enter key pressed.
I've declared a receiver for my app and tried to listen to every bluetooth action in order to identify the command sent from the keyboard to my device, capture that event and trigger certain method in my app, even if it's not open.
I don't know how to achieve this, since when the app is opened, I can override the onKeyDown event and recognize which "key" has the bluetooth keyboard pressed, but can't figure how to achieve that with the app closed. Maybe some intent-filter?
Thanks in advance!
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'm writing a service on android and I need to turn off the screen after a certain time, I tried using all solutions on this thread enter link description here
but none of them worked, thus is there any way i can simulate the power button?
Thank you
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
Is there a cross device hard button in android that a background service can listen to and act when it is pressed/released?
Thanks
No. You can set up a BroadcastReceiver to watch for the CAMERA or MEDIA buttons, but those are not always available -- some devices do not have the CAMERA button, and the MEDIA button is for use with wired headsets.
Sorry!