Javascript 本机功能无法使用PhoneGap-Cordova

Javascript 本机功能无法使用PhoneGap-Cordova,javascript,android,cordova,phonegap-plugins,Javascript,Android,Cordova,Phonegap Plugins,我已经为PhoneGap参考中指定的android本机按钮实现了几个功能: js: var\u-previous; 函数bindCordovaNativeHandlers(){ 文件。添加的监听器(“deviceready”,OnDeviceraddy,false); } 函数ondevicerady(){ document.addEventListener(“菜单按钮”,onMenuKeyDown,false); document.addEventListener(“backbutton”,o

我已经为PhoneGap参考中指定的android本机按钮实现了几个功能:

js:

var\u-previous;
函数bindCordovaNativeHandlers(){
文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
}
函数ondevicerady(){
document.addEventListener(“菜单按钮”,onMenuKeyDown,false);
document.addEventListener(“backbutton”,onBackKeyDown,false);
}
函数onMenuKeyDown(){
//打开功能栏
$('.action')。单击();
}
函数onBackKeyDown(){
//退出函数
var区间=2000,
当前=日期。现在();
_先前=_先前| | 0;
console.log(当前-\u先前);

如果(current-_previous那么,答案是它不起作用,因为正如PhoneGap文档中所述,您应该添加cordova.js的引用,它在构建过程中被注入到项目的根目录中,具体取决于构建所用设备的操作系统

e、 g:


var _previous;
function bindCordovaNativeHandlers(){
    document.addEventListener("deviceready", onDeviceReady, false);
}

function onDeviceReady(){
    document.addEventListener("menubutton", onMenuKeyDown, false);
    document.addEventListener("backbutton", onBackKeyDown, false);
}

function onMenuKeyDown(){
    //open function bar
    $('.action').click();
}

function onBackKeyDown() {
    //quit funciton
    var interval = 2000,
        current = Date.now();

    _previous = _previous || 0;

    console.log(current - _previous);
    if (current - _previous <= interval) {
        navigator.app.exitApp();

    }
    _previous = current;
}
 <gap:plugin name="org.apache.cordova.battery-status" />
    <gap:plugin name="org.apache.cordova.camera" />
    <gap:plugin name="org.apache.cordova.media-capture" />
    <gap:plugin name="org.apache.cordova.console" />
    <gap:plugin name="org.apache.cordova.contacts" />
    <gap:plugin name="org.apache.cordova.device" />
    <gap:plugin name="org.apache.cordova.device-motion" />
    <gap:plugin name="org.apache.cordova.device-orientation" />
    <gap:plugin name="org.apache.cordova.dialogs" />
    <gap:plugin name="org.apache.cordova.file" />
    <gap:plugin name="org.apache.cordova.file-transfer" />
    <gap:plugin name="org.apache.cordova.geolocation" />
    <gap:plugin name="org.apache.cordova.globalization" />
    <gap:plugin name="org.apache.cordova.inappbrowser" />
    <gap:plugin name="org.apache.cordova.media" />
    <gap:plugin name="org.apache.cordova.network-information" />
    <gap:plugin name="org.apache.cordova.splashscreen" />
    <gap:plugin name="org.apache.cordova.vibration" />
<script src="cordova.js"></script>