I wrote an app which starts record audio in response to holding volume up button on phone or headphone, I'm doing it inside dispatchKeyEvent method and it's fine
Problem is, I want to do it when the phone is locked in my pocket, I want to just hold my headphone volume button and start recording, How can I do that in Android? How can you do anything in response to user actions when the phone is locked? For example, how can a music player respond to the user pressing play/pause button on headphone? I know that it is possible, but I don't know how...
Related
I am trying to develop an android application which requires detection of if phone is muted during an incoming call is active(ringing). Some phones have a mute button which instantly mute the sound of the call but does not stop the call (phone is ringing in silent).
Before the call, phone is not muted, but when the call begins, user decides to mute the phone with this button. I want to determine if this situation is happened or not.
I tried to read RINGER_MODE_CHANGED_ACTION but it seems that this button does not change the RINGER_MODE(Maybe I am wrong).
So how can I do that?
I'm creating a music player in android and I want that when I press the headset button, the song will play/pause even if my application is in the background/foreground. I'm using a service class.
How can I trigger the event when the headset button is pressed even if my app is in the background?
Use the guide. There is a description of hardware buttons usage.
I am developing a simple app in which i am the counting of volume button press 3 times. If counter is equal to three then some action will happen.
My problem is when i press the hardware volume button when phone is locked then onReceive() method of BroadcastReceiver is not called. Its working fine when phone is unlocked.
Is there any way or trick that When i press volume up button in locked mode then my counter increase and vice versa.
I researched on this and conclusion is that Its is not possible.
But I did in some way but its not good approach because It will drain the battery too much.
I start the media player in background with zero volume. Now volume keys start working when even mobile is locked. As example Music app in which volume buttons work even when mobile is locked.
Some new Android devices have a mute button like Iphone. Its an actual physical button that allows you to mute an incoming call instead of long pressing the volume down hardware control or the pressing the power button.
my question: What is the keycode event for this or how can i capture it so i can get my app to respond to it ?
I think you're looking for KeyEvent.KEYCODE_MUTE. Note that no flagship Android devices have this button, so you are left to the mercy of whether or not the manufacturer's OS actually sends this event or not.
I have a music player service , using a MediaPlayer set to stream type STREAM_RING. It works fine when i change volume pressing the volume keys as long as the screen is not locked or off. How do i set my service to respond to these keys even in locked screen mode? Thanks.
Based off this question, it looks like it's not possible to capture volume up/down presses when the screen is locked. Android capturing volume up/down key presses in broadcast receiver?