I have installed cordova (version 3.3) and built a sample project using these commands:
$ cordova create hello com.example.hello "HelloWorld"
$ cd hello
$ cordova platform add android
$ cordova build
and imported the project into Eclipse (according to http://cordova.apache.org/docs/en/3.3.0/guide_platforms_android_index.md.html#Android%20Platform%20Guide). I am able to successfully run the app from Eclipse by selecting Run As → Android Application.
Now I want to make use of cordova's notification ablities. I added the plugins (following this guide: http://cordova.apache.org/docs/en/3.3.0/cordova_notification_notification.md.html#Notification) with the commands:
$ cordova plugin add org.apache.cordova.dialogs
$ cordova plugin add org.apache.cordova.vibration
and when I type:
$ cordova plugin ls
it correctly lists the plugins I just added.
I return to Eclipse and paste the following code into assets/www/index.html (overwriting the existing code in index.html):
<!DOCTYPE html>
<html>
<head>
<title>Notification Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
// Empty
}
// Show a custom alert
//
function showAlert() {
navigator.notification.alert(
'You are the winner!', // message
'Game Over', // title
'Done' // buttonName
);
}
// Beep three times
//
function playBeep() {
navigator.notification.beep(3);
}
// Vibrate for 2 seconds
//
function vibrate() {
navigator.notification.vibrate(2000);
}
</script>
</head>
<body>
<p><a href="#" onclick="showAlert(); return false;">Show Alert</a></p>
<p><a href="#" onclick="playBeep(); return false;">Play Beep</a></p>
<p><a href="#" onclick="vibrate(); return false;">Vibrate</a></p>
</body>
</html>
When I deploy it to a device, it displays three links (Show Alert, Play Beep and Vibrate). When I press on these I expect the corresponding native notification to occur, but it doesn't. Instead I get the following error messages (displayed in LogCat):
Show alert: Uncaught ReferenceError: showAlert is not defined:45
Play Beep: Uncaught ReferenceError: playBeep is not defined:46
Vibrate: Uncaught ReferenceError: vibrate is not defined:47
How am I supposed to fix these errors?
Thanks in advance!