简体   繁体   中英

Native functionality no working with PhoneGap - Cordova

I have implemented several functions for the android native buttons as specified in the PhoneGap referrence:

js:

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;
}

html:

in order to not cause any suspicision from my users, I would like to require the minimal amount of permissions (cordova plugins are translated into android permissions).

Are there any cordova plugins that are required for that functionality?

Plugins that I've removed on the last build:

 <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" />

Well, the answer is that it didn't work since, as noted in the PhoneGap documentation, you should add a reference for cordova.js, which is injected into the root of your project during the build process depending on the operating system of the device the build is for.

eg:

<script src="cordova.js"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM