Apache Cordova - 检测 Android 主页按钮按下

Apache Cordova - Detect Android Home button press

我有一个使用 angularjs 的项目,我使用 Cordova 将项目构建到 android 应用程序。在我的项目中,我添加了 ngCordova 并且我想在客户端单击设备中的主页按钮时使用事件。

我阅读了 http://ngcordova.com/docs/plugins/ 但我没有找到任何我需要的东西。有人可以帮助我或知道我可以使用什么吗?

cordova 中没有按下主页按钮的事件。您可以检测应用程序恢复和暂停事件:

 // device APIs are available
//  be sure to add the listener in the device ready event
function onDeviceReady() {
    document.addEventListener("pause", onPause, false);
    document.addEventListener("resume", onResume, false);
}

//runs when the app is on background
function onPause() {
    // Handle the pause event
}

//runs when the app resumes
function onResume() {
    // Handle the resume event
}

可以在 official cordova documentation

上找到更多信息