Skip to content

Commit

Permalink
[Android] suppressVolumeIndicator consumes all key press events, not …
Browse files Browse the repository at this point in the history
…just volume keys #12

Changes:
- implemented the required fix for [Android] suppressVolumeIndicator consumes all key press events, not just volume keys #12 issue
  • Loading branch information
ryaa committed Jul 22, 2024
1 parent 6bb2aee commit 6e00198
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 6e00198

Please sign in to comment.