JavaFX Android port Listen for volume button presses -


i'm trying develop android app javafx. there way listen volume button presses on phone can launch code whenever press volume buttons?

you can listen various key codes, e.g.

  • keycode.escape == back-button
  • keycode.volume_up / keycode.volume_down
  • keycode.home - i'm not sure, haven't tested it
  • keycode.context_menu - i'm not sure, haven't tested it

in application-extending main class this:

@override public void start(stage stage) throws exception {     // init scene , ui     scene.addeventfilter(keyevent.any, this::handleglobalkeyevents);     // whatever want }  private void handleglobalkeyevents(keyevent event) {     // use more specific key event type     // --> keyevent.key_released == event.geteventtype()     // --> keyevent.key_pressed == event.geteventtype()     // without it, react on both events, doing 1 operation     if (event.getcode().equals(keycode.escape) && keyevent.key_released == event.geteventtype()) {         if (backhandler != null)             backhandler.back();         event.consume();     } } 

regards, daniel


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -