捕获返回键preSS上的PhoneGap为AndroidpreSS、PhoneGap、Android

由网友(沵卟值棏)分享简介:我使用的PhoneGap的Andr​​oid应用程序开发和我被困在捕捉返回键preSS设备上!我什么都试过其他线程,并从官方的wiki页面,但似乎没有任何工作! :(I am using PhoneGap for Android Application development and I'm stuck at cap...

我使用的PhoneGap的Andr​​oid应用程序开发和我被困在捕捉返回键preSS设备上!我什么都试过其他线程,并从官方的wiki页面,但似乎没有任何工作! :(

I am using PhoneGap for Android Application development and I'm stuck at capturing the back key press on the device! I tried everything from other threads and from the official wiki page but none seem to work! :(

我可以捕捉keyEvent.menuTrigger和keyEvent.searchTrigger菜单和搜索键,但似乎无法捕捉后退按钮preSS!我想keyEvent.backTrigger类似,但它没有工作!添加事件侦听器backKeyDown事件也不管用!

I could capture menu and search keys with keyEvent.menuTrigger and keyEvent.searchTrigger but can't seem to capture the back button press! I tried keyEvent.backTrigger similarly but it didn't work! Adding event listener for 'backKeyDown' event doesn't work either!

下面是我的code:

BackButton.override();
    document.addEventListener('backKeyDown', function(e) {
  console.log('Caught it!');
}, false);
keyEvent.searchTrigger= searchPressed;
keyEvent.menuTrigger=menuPressed;
keyEvent.backTrigger=backPressed;

控制台说:

Line 1 : Uncaught TypeError: Cannot call method 'backTrigger' of undefined

难道这不是意味着something.backTrigger()被调用,但该对象的东西不存在。那是什么东西?或者是有什么办法在吗?

Doesn't that mean something.backTrigger() is being called but the object something doesn't exist. What is that something? Or is there any way around?

试过同KeyEvent的太多,没有运气! 请帮帮忙!

Tried the same with KeyEvent too, with no luck! Please help!

在此先感谢! :)

推荐答案

PhoneGap的维基页关于Android按钮处理程序已更新为PhoneGap的0.9.5:

PhoneGap Wiki page about Android button handler has been updated for PhoneGap 0.9.5 :

// This is your app's init method. Here's an example of how to use it
function init() {
    document.addEventListener("deviceready", onDR, false);
} 

function onDR(){
    document.addEventListener("backbutton", backKeyDown, true);
    //boot your app...
}

function backKeyDown() {
    // do something here if you wish
    // alert('go back!');
}

我工程与PhoneGap的0.9.6

Works for me with PhoneGap 0.9.6

您还可以处理其他按键与菜单按钮和 searchbutton 的事件。

You can also handle others buttons with menubutton and searchbutton events.

阅读全文

相关推荐

最新文章