How can a long key press (volume keys) be detected in Android when the screen is off? Is there any way to do this?
This is not possible, sorry. The only thing that could possibly detect a long press of a volume button is a foreground activity. This also assumes that the device has hardware volume buttons, and not all devices do.
Related
I want to detect long presses in volume key in a service. Here are my options:
A) Let the user control volume from the lock screen
I wan't to detect if the user has held down the volume button in a service while the screen is off. I already tried (for 2 days) doing it with contentObserver, but the problem is that contentObserver detects volume changes, and volume doesn't change when the screen is off. Is there any way I can let the user control volume from the lock screen?
B) Detect long press for volume button from service
How can I do this? Are there any broadcast receiver's that I can use while the screen is off? Is there a way to implement the dispatchKeyEvent in a service?
I have seen this, but for me the second answer doesn't work in the background. I think the easiest way would be option A because I already have everything set up for when the user changes volume, so can I let the user control volume from lock screen? If not, is there anything else I can do?
Thanks so much,
Ruchir
I am a beginner in programming android.
Is there any way to combine two long press buttons with an Android service and react to that?
I want to combine two long press buttons (home & volume down ) for activate wifi even if the phone is locked.
thanks.
Rather than connecting to the long press listener..
Connect to the button press listener.
Check when the button is pressed down, and when it is lifted up.
Measure the time between these 2 events. Was it long enough to be classed as a long press?
Were both buttons pressed down long enough at the same time?..
If you want to trigger while they are down still, just ensure the up event hasnt fired yet after 2 seconds for example.
I have an activity that shows up when the phone screen goes to sleep/turns off ie turns black.
For some reason, the phone turns on when the volume buttons or the camera buttons are pressed. By turns on, I mean the screen wakes up or comes back from the black screen state.
I've tried using dispatchKeyEvent(KeyEvent event) and the buttons are disabled on the activity, but they still wake up the phone.
You could try overriding the onKeyDown(KeyEvent) method and change what happens for those keys. However, I'm not too optimistic as if you're running an activity, it will be in an inactive state when the display is off, and also it could be that the phone is hard wired to wake up on those buttons. It could be device specific. Hard to say. Try that out and let me know how it goes, I'm currious
Icons of app can shake and delete app by long press in Iphone's HomeShell, I want to implement this effect. I knew the rotateAnimation is like the effect in android. But But using rotateAnimation bringed some problems, such as system performence. I want to do shaking effect on the drawable of ImageView. How can I implement is? Any help is grateful!
I am trying to develop an application in which I want to know when the camera button(if the phone has one),has been pressed for feature phones like Series60 using J2ME.I dont want to take a snapshot or take a video.I just want to know when the hardware button has been pressed.
I have been unable to find a proper way for this.Your help is greatly appreciated.
Create a canvas, listen for keypresses and output all events to the screen. If no event occurs when you press the camera key then you can't do it.