Skip to content

Commit

Permalink
Merge pull request #13 from capacitor-community/bugfix/12-android-sup…
Browse files Browse the repository at this point in the history
…pressvolumeindicator-consumes-all-key-press-events-not-just-volume-keys

[Android] suppressVolumeIndicator consumes all key press events, not just volume keys #12
  • Loading branch information
ryaa authored Jul 23, 2024
2 parents 6bb2aee + 6e00198 commit 3bb1baf
Showing 1 changed file with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,26 @@ public void watchVolume(final PluginCall call) {
new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, android.view.KeyEvent event) {
boolean isKeyUp = event.getAction() == KeyEvent.ACTION_UP;
JSObject ret = new JSObject();

if (isKeyUp) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
ret.put("direction", "up");
call.resolve(ret);
return true;
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
ret.put("direction", "down");
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
boolean isKeyUp = event.getAction() == KeyEvent.ACTION_UP;
if (isKeyUp) {
JSObject ret = new JSObject();
ret.put("direction", keyCode == KeyEvent.KEYCODE_VOLUME_UP ? "up" : "down");
call.resolve(ret);
return true;
}
// NOTE: we return suppressVolumeIndicator value for volume buttons event actions only
// therefore, when suppressVolumeIndicator is true, for a key event that typically controls the system volume,
// the system volume indicator will not be displayed by default.
// This is because returning true from onKey() indicates that your application has consumed
// the key event and no system-level action should occur in response to that event.
return suppressVolumeIndicator;
}

// NOTE: we return suppressVolumeIndicator value for any event actions but KeyEvent.ACTION_UP (which is handled above)
// therefore, when suppressVolumeIndicator is true, for a key event that typically controls the system volume,
// the system volume indicator will not be displayed by default.
// This is because returning true from onKey() indicates that your application has consumed
// the key event and no system-level action should occur in response to that event.
return suppressVolumeIndicator;
return false;
}
}
);


isStarted = true;
}

Expand Down

0 comments on commit 3bb1baf

Please sign in to comment.