最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Phonegap navigator.notifications does nothing - Stack Overflow

matteradmin4PV0评论

Starting to play with phonegap for the android and am not able to get anything in the navigator.notifications to work (actually looks like navigator.<anything> is not working). In my JS I have tried

navigator.notification.vibrate(1000);
navigator.notification.vibrate();
navigator.notification.alert("one", "two", "three");
navigator.notification.beep(1);

none of them do anything, the app just continues right on past them like nothing ever happened. If I alert(navigator) I get [object object] but alert(navigator.notification) gives null.

Starting to play with phonegap for the android and am not able to get anything in the navigator.notifications to work (actually looks like navigator.<anything> is not working). In my JS I have tried

navigator.notification.vibrate(1000);
navigator.notification.vibrate();
navigator.notification.alert("one", "two", "three");
navigator.notification.beep(1);

none of them do anything, the app just continues right on past them like nothing ever happened. If I alert(navigator) I get [object object] but alert(navigator.notification) gives null.

Share Improve this question edited Sep 1, 2011 at 14:31 Lee Quarella asked Aug 31, 2011 at 22:20 Lee QuarellaLee Quarella 4,7425 gold badges44 silver badges68 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

PhoneGap for Android supports all three notification methods you mentioned. For me it looks like you try to run them before PhoneGap is ready (so before navigator.notification object is initialized). Make sure your code is not executed before PhoneGap notify deviceready event. Just for test you can try to run a code like this:

document.addEventListener("deviceready", function(){
   navigator.notification.vibrate(1000);
   navigator.notification.alert("Hello");
   navigator.notification.beep(1);   
}, false);

Please also notice that in your example there is a mistake in alert method invocation. The second parameter is a callback (executed after user press/taps button on alert), so you shouldn't pass a string there.

Post a comment

comment list (0)

  1. No comments so far