Android PhoneGap アプリケーションを手動で一時停止することはできますか? 誰かがボタンをクリックしたときに、アプリケーションを一時停止してバックグラウンドに移行する必要があります。使用navigator.app.exitApp();
しましたが、アプリケーションが完全に閉じます。ネイティブの戻るボタンで行われるように、アンロードするだけでアプリケーションを閉じたくありません。助けてください、ありがとう。
3627 次
2 に答える
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", []);
}
};
});
と:
// 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");
}
);
}
Android ネイティブの 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;
}
}
次のように呼び出します。
homeButton();
それは動作し、私のレポの一部です: https://github.com/teusinkorg/jpHolo/
于 2013-09-26T13:06:44.510 に答える