使用 phonegap,您可以转义所有 java 代码,正如您将在以下代码中看到的那样,您不需要任何 java 代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Cordova Menu Button Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.3.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Call onDeviceReady when Cordova is loaded.
// At this point, the document has loaded but cordova-2.3.0.js has not.
// When Cordova is loaded and talking with the native device,
// it will call the event `deviceready`.
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// Cordova is loaded and it is now safe to make calls Cordova methods
function onDeviceReady() {
// Register the event listener
document.addEventListener("menubutton", onMenuKeyDown, false);
}
// Handle the menu button
function onMenuKeyDown() { alert("menu btn pressed");
}
</script>
</head>
<body onload="onLoad()">
</body>
</html>
不要为此功能使用插件,只需转到主文档即可。您还可以找到其他事件,例如:
- 设备就绪
- 暂停
- 恢复
- 在线的
- 离线
- 返回键
- 电池关键
- 电量不足
- 电池状态
- 菜单按钮
- 搜索按钮
- 开始呼叫按钮
- 结束通话按钮
- 音量下键
- 音量增大按钮