捕获返回键preSS上的PhoneGap为Android

捕获返回键preSS上的PhoneGap为Android

本文介绍了捕获返回键preSS上的PhoneGap为Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的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.

这篇关于捕获返回键preSS上的PhoneGap为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 21:10