[Android-development] Handling Android volume keys

Martin Leutelt martin.leutelt at basyskom.com
Tue Oct 18 09:55:23 CEST 2016

From:   Tomasz Bojczuk <seelook at gmail.com> 
 To:   <android-development at qt-project.org> 
 Sent:   10/18/2016 9:28 AM 
 Subject:   [Android-development] Handling Android volume keys 


QKeyEvent doesn't support Android volume keys. How to handle them then?
I found Java code:

public boolean dispatchKeyEvent(KeyEvent event) {
    int action = event.getAction();
    int keyCode = event.getKeyCode();
    switch (keyCode) {
        case KeyEvent.KEYCODE_VOLUME_UP:
            if (action == KeyEvent.ACTION_DOWN) {
                // emit something for c++
            return true;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (action == KeyEvent.ACTION_DOWN) {
                // emit something for c++
            return true;
            return super.dispatchKeyEvent(event);

and with available "Android on Qt "episodes I hope to be able to call my c++ part from that. 
But how and where the above code should be run?


This code should be put into your applications' activity Java code. Your activity will need to inherit from QtActivity.
You'll also need to add static native methods to your activity which you call in the appropriate case. 
That allows you to make the transition into the C++ part of your application which registers its functions with the JNI in JNI_OnLoad (see https://www.kdab.com/qt-android-episode-5/).

Btw: the 'development' mailing list is for the development of Qt itself, you should post to the 'interest' mailing list.


Android-development mailing list 
Android-development at qt-project.org 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/android-development/attachments/20161018/b8afa902/attachment.html>

More information about the Android-development mailing list