Android的音量键事件捕获 [英] Android Volume Key Event Capture

查看:895
本文介绍了Android的音量键事件捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个应用程序机器人 ..

I am currently developing an app for android..

我怎么能捕捉键事件,当用户preSS的android手机

how i can capture the volume key event when user press in android phone

我使用的电话差距

推荐答案

使用下面的code拿到钥匙事件

Use the below code to get the key event

使用这种code在现有的Java类

Use this code in your existing java class

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    //If volume down key
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        this.loadUrl("javascript:cordova.fireDocumentEvent('volumedownbutton');");
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        this.loadUrl("javascript:cordova.fireDocumentEvent('volumeupbutton');");
        return true;
    } else {
        //return super.onKeyDown(keyCode, event); 
    }
    //return super.onKeyDown(keyCode, event);

    return true;
}

和在HTML页面中使用这个下面

and using this below in your html page

document.addEventListener("volumeupbutton", onVolumeUpKeyDown, false);  

document.addEventListener("volumedownbutton", volumedownbutton, false);

function    onVolumeUpKeyDown()
{
    alert("Working Up")     
}

function    volumedownbutton()
{
    alert("Working Down")       
}

我得到这个答案从这里<一个href="http://stackoverflow.com/questions/9770901/phonegap-event-volumeupbutton-and-volumedownbutton-is-not-working">http://stackoverflow.com/questions/9770901/phonegap-event-volumeupbutton-and-volumedownbutton-is-not-working

这篇关于Android的音量键事件捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆