在Android Phonegap中手动暂停应用程序

Sar*_* DR 5 android cordova

是否可以手动暂停Android PhoneGap应用程序?当有人点击按钮时,我需要暂停应用程序并转到后台.我用过,navigator.app.exitApp();但它完全关闭了应用程序.我不想像卸载本机后退按钮一样关闭应用程序.请帮忙,谢谢.

小智 1

在你的 JavaScript 中:

// HomeButton
cordova.define("cordova/plugin/homebutton", function (require, exports, module) {
    var exec = require("cordova/exec");
    module.exports = {
        show: function (win, fail) {
            exec(win, fail, "HomeButton", "show", []);
        }
    };
});
Run Code Online (Sandbox Code Playgroud)

和:

// HomeButton
function homeButton() {
    var home = cordova.require("cordova/plugin/homebutton");
    home.show(
        function () {
            console.info("PhoneGap Plugin: HomeButton: callback success");
        },
        function () {
            console.error("PhoneGap Plugin: HomeButton: callback error");
        }
    );
}
Run Code Online (Sandbox Code Playgroud)

在 Android Native 上的 Java 中:

package org.apache.cordova.plugins;

import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;

import android.content.Intent;
import android.util.Log;

public class HomeButton extends CordovaPlugin {

    public static final String LOG_PROV = "PhoneGapLog";
    public static final String LOG_NAME = "HomeButton Plugin";

    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
        Log.d(LOG_PROV, LOG_NAME + ": Simulated home button.");
        Intent i = new Intent(Intent.ACTION_MAIN);
        i.addCategory(Intent.CATEGORY_HOME);
        this.cordova.startActivityForResult(this, i, 0);
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
        return true;
    }

}
Run Code Online (Sandbox Code Playgroud)

调用它:

homeButton();
Run Code Online (Sandbox Code Playgroud)

它有效,并且是我的存储库的一部分: https: //github.com/teusinkorg/jpHolo/