I need to receive long sound button press event even if my phone is locked.
I tried using SettingsContentObserver and AudioManager but it only works when the music is playing.
Source: https://stackoverflow.com/a/15292255/4757621
Currently I am creating wakelock in OnCreate method to keep CPU running when phone is locked but still, no success.
Any ideas?
Related
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...
I'm using the AlarmManager for playing a sound (with MediaPlayer) at a given time.
Unfortunately the play() method doesn't seem to work when the phone is locked.
I'm developing on Marshmallow, so I already solved the Doze issues by using setAlarmClock() and using a CPU wake lock (the Partial wake lock). The strange thing is that the activity launches over the lockscreen (what it should do) when the alarm fires, but the play() method of the MediaPlayer doesn't play.
When I rotate the screen, the music starts playing.
How can I solve this, so the music start playing when the activity is launched, altough the phone is locked?
Because of the Dose Mode. When you rotate a screen Dose mode is disabled. Try to add your app in white list
I have implemented a media player in a service and it works fine when i have a playlist is on as long as the screen is on. However, when the screen is locked, playback stops after a couple of songs and i have to press play again in order to continue.
Is there anything that causes the service to stop or the media player to pause playback when the screen is off, even after I add a partial wake lock?
I have developed a music player application,which has a service(AudioPlayerService) which will be running in the background.Service will be started when play button is pressed. It will run in the background even though application goes to background.
Playback can be stopped by bringing the app to foreground and press the stop button, which makes the music to stop and stops the AudioPlayerService too. everything works fine.
Otherway i can use the Force Stop from Settings app (Settions->Application->Downloaded->Select the App->Press Force Stop Button).
I am able to stop the application and music also stopped playing.
But If i use Stop button from Settings App (Settings->Applications->Running->Select the App -> Press Stop), application is terminated and my app is removed from the running app list, but music is still playing in the background.
I am not sure why Running Tab Stop Button does not stop the music.
Any one help me if i need to handle anything in my service to class to stop the playback.
I am testing in Samsung Galaxy S2 with Android 4.0.3
Thanks
Sasikumar JP
On the onDestroy override method of your service use your mediaplayer object to stop the media from playing.
#Override
OnDestroy{
mediaplyer.stop();
}
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.