绑定到移动设备的硬件按钮 [英] Bind to mobile device hardware buttons

查看:87
本文介绍了绑定到移动设备的硬件按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用jQuery mobile绑定到移动设备的硬件按钮? 如果是这样,是否有任何代码示例?

Is it possible to bind to hardware buttons of mobile device using jQuery mobile? If so, are there any code examples?

我特别想绑定到移动设备的音量增大和减小按钮以及使用这些按钮滚动页面.

Particulary I am interested in binding to mobile device volume up and down buttons and scrolling pages using those buttons.

这是关于android和硬件后退按钮的类似问题控制硬件后退按钮jquery mobile

Here is similar question regarding android and hardware back button Take control of hardware back button jquery mobile

现在,我想知道如何在跨平台的情况下对音量进行上下调幅吗?

Now I am wondering how to do same thing for volume up and down but crossplatform?

推荐答案

简短的回答不是,您不能仅使用jQuery Mobile来做到这一点.

Short answer is no, you can't do that with a jQuery Mobile only.

现在,我假设您正在创建一个移动应用程序,通过移动应用程序,我的意思是混合android/iPhone应用程序,而不是您的Web应用程序的移动版本.如果我是正确的话,您可能会使用Phonegap/Cordova框架包装程序,该包装程序将作为HTML/CSS/JS和natuve应用程序之间的包装程序.

Now I would assume you are creating a mobile application, and by mobile application I mean hybrid android/iPhone app and not a mobile version of your web app. If I am correct you will probably use a Phonegap/Cordova framework wrapper which will server as a wrapper between your HTML/CSS/JS and a natuve app.

有关Phonegap/Cordova框架的更多信息,请参见: http://cordova.apache.org/

More about Phonegap/Cordova framework can be found here: http://cordova.apache.org/

jQuery Mobile和Phonegap是标准组合,您可以找到很多有关教程的方法.

jQuery Mobile and Phonegap is a standard mix, you can find a lot of how to tutorials.

但是回到您的问题,这是如何使用Phonegap将音量增大和音量减小事件绑定到jQuery移动代码:

But back to your question, here's how you can bind volume up and volume down event using Phonegap to jQuery mobile code:

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

function onVolumeDownKeyDown() {
    // Handle the volume down button
}

和:

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

function onVolumeUpKeyDown() {
    // Handle the volume up button
}

也请看一下我的另一篇短篇文章,如何使用jQuery mobile处理电话间隔事件:

Also take a look at my other short article how to handle phonegap events with jQuery mobile:

https://stackoverflow.com/a/14010308/1848600

有关音量增大/音量减小事件的更多信息,请参见: http://docs.phonegap.com/en/1.2.0/phonegap_events_events.md.html

More about volume up/volume down events can be found here: http://docs.phonegap.com/en/1.2.0/phonegap_events_events.md.html

这篇关于绑定到移动设备的硬件按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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