我正在尝试监控安卓系统(4.4.2 -三星S3)上的菜单按钮,但是Ionic event (或者底层的Cordova event)不能工作:
$ionicPlatform.on("menubutton", function () {
// do our stuff here (never gets called)
});有没有人能做到这一点?运行Ionic platform 1.0.0,所有其他事件都按预期触发。
发布于 2016-06-16 05:52:47
文档里少了一行。
document.addEventListener("deviceready", function() {
...
navigator.app.overrideButton("menubutton", true); // <-- Add this line
document.addEventListener("menubutton", yourCallbackFunction, false);
...
}, false);https://issues.apache.org/jira/browse/CB-9949#comment-14989073
发布于 2015-06-16 03:19:50
试试这个:在.run()
$ionicPlatform.ready(function() {
//...
if (window.cordova) {
$cordovaSplashscreen.hide();
document.addEventListener("menubutton", myApp.onHardwareMenuKeyDown, false);
}
/...然后在控制器中:
$scope.onHardwareMenuKeyDown = function() {
alert('menu button is working');
}做某事的另一种方式:
angular.module('myApp', ['ngCordova', 'ionic', 'myApp.controllers'])
.run(function($ionicPlatform, $rootScope, $state, $localstorage,$ionicSideMenuDelegate ) {
$ionicPlatform.ready(function() {
document.addEventListener("menubutton", onMenuKeyDown, false);
function onMenuKeyDown() {
console.log("some menu pops pup!! ");
// here change the view , etc...
$rootScope.$apply();
}
});
})https://stackoverflow.com/questions/30790419
复制相似问题