Listen to volume buttons in background service?
Judging by the couple of other questions about this topic, no.
Other question 1,
Other question 2
Services simply do not receive KeyEvent callbacks.
Listen to volume buttons in background service?
Judging by the couple of other questions about this topic, no.
Other question 1,
Other question 2
Services simply do not receive KeyEvent callbacks.
Android How to listen for Volume Button events?
I don't know if you can get long press events for the hardware keys.
I've used this code to listen for the volume button before.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN){
// Do something
}
return true;
}
If that doesn't work for you let us know what device you are testing on.
Kotlin
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
// Do something
}
return true
}
how to create a service, that would be listening to the volume button?
What do you think, is that possible?
No. You cannot listen for volume button presses in a service.
Related Topics
How to Add Calendar Events in Android
How to Force Use of Overflow Menu on Devices With Menu Button
How to Refresh Mediastore on Android
How to Make Surfaceview Transparent
Android Material and Appcompat Manifest Merger Failed
Android: How to Bind Spinner to Custom Object List
How to Underline Text in an Android Layout
Android - Set Max Length of Logcat Messages
Gradle: Execution Failed for Task ':Processdebugmanifest'
Onitemclicklistener Not Working in Listview
How to Return a Result (Startactivityforresult) from a Tabhost Activity
What's the Best Way to Limit Text Length of Edittext in Android
Check Android Application Is in Foreground or Not
How to Prevent Screen Capture in Android
How to Install Trusted Ca Certificate on Android Device
Warning: This Asynctask Class Should Be Static or Leaks Might Occur