1. MSPL Dev's Avatar
    We have Android TV (ATV) box running on Android version 8.1 and above. We need to get key events for volume keys when pressed from ATV remote. Unfortunately we couldn't get volume key events from Android version 8.1 & Above. But we can get volume key events from Android version Nougat 7.0 box.

    Question : How I need to capture volume key events in Android TV box versions 8.1 and 9 [pie] ?

    We have tried following callback API onKeyDown(), onKeyUp(), dispatchKeyEvent(), onKeyLongPress() and onKeyEvent() in activity class.
    @override
    public boolean onKeyDown(int keyCode, KeyEvent event){

    Log.d(TAG,"Key code pressed: " + event.getKeycode);
    }

    Expected output : Key code pressed: 25
    Key code pressed: 24

    Actual output : onkeydown not get triggered for volume keys.
    07-04-2019 12:43 AM
  2. B. Diddy's Avatar
    I moved this to the Android TV forum for more specific traffic.
    07-05-2019 01:11 AM
  3. videostorm's Avatar
    Connect to the device via ADB, they logcat the output and look for what keyevents are being triggered.

    If the kernel "consumes" the keyevent, it will not be forwarded to the foreground app.
    07-31-2019 01:51 PM
  4. MSPL Dev's Avatar
    Connect to the device via ADB, they logcat the output and look for what keyevents are being triggered.

    If the kernel "consumes" the keyevent, it will not be forwarded to the foreground app.
    Logcat able to see some of system UI events related volume bar.

    2019-08-05 14:24:19.786 3441-3631/? D/vol.VolumeDialogControl: onReceive VOLUME_CHANGED_ACTION stream=0 level=4 oldLevel=4
    2019-08-05 14:24:19.786 3441-3631/? D/vol.VolumeDialogControl: onReceive VOLUME_CHANGED_ACTION stream=3 level=13 oldLevel=12
    2019-08-05 14:24:19.787 4658-4775/? I/chromium: [4658:4775:INFO:media_manager_impl.cc(464)] New volume for MEDIA: 0.866667
    2019-08-05 14:24:19.788 4658-4658/? I/chromium: [4658:4658:INFO:metrics_recorder.cc(307)] Count histogram: SetVolumeLevel.E8C28D3C, sample=86, boundary=101
    2019-08-05 14:24:19.792 3441-3441/? I/vol.Events: writeEvent show_dialog volume_changed keyguard=false
    2019-08-05 14:24:20.591 3441-3631/? D/vol.VolumeDialogControl: onReceive VOLUME_CHANGED_ACTION stream=10 level=14 oldLevel=13
    2019-08-05 14:24:20.600 3441-3631/? D/vol.VolumeDialogControl: onReceive VOLUME_CHANGED_ACTION stream=9 level=14 oldLevel=13
    2019-08-05 14:24:20.600 3441-3631/? D/vol.VolumeDialogControl: onReceive VOLUME_CHANGED_ACTION stream=9 level=14 oldLevel=13
    2019-08-05 14:24:20.600 3441-3631/? D/vol.VolumeDialogControl: onReceive VOLUME_CHANGED_ACTION stream=8 level=14 oldLevel=13
    2019-08-05 14:24:20.601 3441-3631/? D/vol.VolumeDialogControl: onReceive VOLUME_CHANGED_ACTION stream=7 level=7 oldLevel=6
    2019-08-05 14:24:20.601 3441-3631/? D/vol.VolumeDialogControl: onReceive VOLUME_CHANGED_ACTION stream=6 level=14 oldLevel=13
    2019-08-05 14:24:20.601 3441-3631/? D/vol.VolumeDialogControl: VOLUME_CHANGED_ACTION up
    2019-08-05 14:24:20.606 3441-3631/? I/vol.Events: writeEvent level_changed STREAM_BLUETOOTH_SCO 14
    2019-08-05 14:24:20.606 3441-3631/? D/vol.VolumeDialogControl: onReceive VOLUME_CHANGED_ACTION stream=5 level=7 oldLevel=6
    2019-08-05 14:24:20.606 3441-3631/? D/vol.VolumeDialogControl: onReceive VOLUME_CHANGED_ACTION stream=0 level=5 oldLevel=4
    2019-08-05 14:24:20.606 3441-3631/? I/vol.Events: writeEvent level_changed STREAM_VOICE_CALL 5
    2019-08-05 14:24:20.606 3441-3631/? D/vol.VolumeDialogControl: onReceive VOLUME_CHANGED_ACTION stream=3 level=14 oldLevel=13
    2019-08-05 14:24:20.606 3441-3631/? I/vol.Events: writeEvent level_changed STREAM_MUSIC 14
    2019-08-05 14:24:20.607 4658-4791/? I/chromium: [4658:4791:INFO:volume_control_android.cc(218)] SetVolumeOnThread: level=1 (1)
    2019-08-05 14:24:20.607 4658-4791/? I/chromium: [4658:4791:INFO:audio_sink_manager.cc(77)] SetTypeVolumeDb: level_db=1 type=kOther
    2019-08-05 14:24:20.613 4658-4791/? I/chromium: [4658:4791:INFO:volume_control_android.cc(218)] SetVolumeOnThread: level=0.933333 (1)
    2019-08-05 14:24:20.613 4658-4791/? I/chromium: [4658:4791:INFO:audio_sink_manager.cc(77)] SetTypeVolumeDb: level_db=1 type=kMedia
    2019-08-05 14:24:20.616 3441-3441/? I/vol.Events: writeEvent show_dialog volume_changed keyguard=false
    08-05-2019 03:54 AM

Similar Threads

  1. Replies: 1
    Last Post: 07-05-2019, 01:11 AM
  2. The Messenger icon on my home screen doesn't show messages.
    By Android Central Question in forum Ask a Question
    Replies: 1
    Last Post: 07-04-2019, 03:57 PM
  3. Cant receive messages from one contact
    By Android Central Question in forum Ask a Question
    Replies: 2
    Last Post: 07-04-2019, 03:53 PM
  4. Replies: 2
    Last Post: 07-03-2019, 09:51 PM
  5. Anyone failed the Associate Android Developer Exam?
    By Android Central Question in forum Ask a Question
    Replies: 1
    Last Post: 07-03-2019, 09:46 PM
LINK TO POST COPIED TO CLIPBOARD