2016-07-16 50 views
1

我有一个项目,它使用angularjs和我使用科尔多瓦建立项目到Android应用程序。在我的项目中,我添加了ngCordova,并且我想在客户端单击设备中的主页按钮时使用事件。阿帕奇科尔多瓦 - 检测Android主页按钮

我试过http://ngcordova.com/docs/plugins/但我没有找到任何我需要的东西。有人可以帮助我,或有任何想法我可以使用?

+0

就可以找到我所知,还没有明确的事件,但你可以使用暂停事件。每次应用程序进入后台时都会调用它(按Home键时就是这种情况)。看看[文档在这里](https://cordova.apache.org/docs/en/latest/cordova/events/events.html#pause)。 – Phonolog

+0

我知道,但是当我有消息时,暂停事件是活动的,我不想那样。 – phuchoangmai

回答

4

科尔多瓦没有Home按钮按下的事件。您可以检测应用程序的简历和暂停的事件:

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

+0

哦。但是,如果我在使用函数onPause或onResume时有消息,此函数将激活。当我收到消息 – phuchoangmai

+0

@NguyễnPhúc时,我不想在onPause或onResume功能激活,您必须在暂停和恢复时使用您自己的逻辑运行。例如'if(message){//什么也不做} else {//做事}' – Akis

+0

哦,对不起。我解决了这个错误。感谢Akis。我照你的说法做了:) – phuchoangmai