Skip to content Skip to sidebar Skip to footer

Phonegap Event Volumeupbutton And Volumedownbutton Is Not Working

I am using PhoneGap Api 1.4.1 and also I tried with 1.5.0, The PhoneGap Event volumeupbutton and volumedownbutton is not working, neither it works on android device nor it works o

Solution 1:

You can do the following, to get the volume button running with android:

@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {

    //If volumedown keyif (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        this.loadUrl("javascript:cordova.fireDocumentEvent('volumedownbutton');");
        returntrue;
    } elseif (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        this.loadUrl("javascript:cordova.fireDocumentEvent('volumeupbutton');");
        returntrue;
    } else {
        //return super.onKeyDown(keyCode, event); 
    }
    //return super.onKeyDown(keyCode, event);returntrue;
}

@Overridepublic boolean onKeyUp(int keyCode, KeyEvent event) {
    LOG.d(TAG, "KeyUp has been triggered on the view" + keyCode);
    // If back keyif (keyCode == KeyEvent.KEYCODE_BACK) {
        this.loadUrl("javascript:cordova.fireDocumentEvent('backbutton');");
        returntrue;
    }
    // Legacyelseif (keyCode == KeyEvent.KEYCODE_MENU) {
        this.loadUrl("javascript:cordova.fireDocumentEvent('menubutton');");
        returntrue;
    }
    // If search keyelseif (keyCode == KeyEvent.KEYCODE_SEARCH) {
        this.loadUrl("javascript:cordova.fireDocumentEvent('searchbutton');");
        returntrue;
    }
    returnfalse;
}

I copied this code from a cordova bug report. This code is valid for cordova 2.0. I thin you'll have to change "cordova.fireDocumentEvent" to "phonegap.fireDocument" or "PhoneGap.fireDocumentEvent"

update: Just wrote a small blog-post about the bug, that was solved by the code above. The link to the Cordova-Issue-Tracker can be found in that post: http://christian-kuetbach.de/blog/post/13

update 2: The Issue seems to be fixed within cordova 1.9: https://issues.apache.org/jira/browse/CB-871

Hope this helps.

Post a Comment for "Phonegap Event Volumeupbutton And Volumedownbutton Is Not Working"