Reputation: 1137
I am a new PhoneGap programmer. navigator.notification.alert() has not working on Android using phonegap. But it works on IPhone and WP7. I am developing this app in Windows Phone 7.
Thanks for your help
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Cordova WP7</title>
<link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title"
charset="utf-8" />
<!--<script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>-->
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript">
function doAlert() {
var message = "This is an Alert dialog";
var title = "Attention!";
navigator.notification.alert(message, title);
};
</script>
</head>
<body>
<h1>
Cordova Tests</h1>
<div id="info">
<a href="#" onclick="doAlert()">Click Me</a>
</div>
</body>
</html>
Finally, i got the solution.
Solution:
Before we build the phonegap code(in build.phonegap.com) we need to delete cordova-2.0.0.js file. If we delete this cordova-2.0.0.js, phonegap code is working on andriod.
Upvotes: 3
Views: 4468
Reputation: 820
You have to wait for DeviceReady
:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale = 1.0, maximum-scale=1.0, user-scalable=no" />
<script type="text/javascript" charset="utf-8" src="windows/cordova-2.0.0.js"></script>
<script type="text/javascript" charset="utf-8">
var deviceReady = false;
function init() {
document.addEventListener("deviceready", function () {
deviceReady = true;
}, false);
window.setTimeout(function () {
if (!deviceReady) {
alert("Error: Phonegap did not initialize. Demo will not run correctly.");
console.log("Error: Phonegap did not initialize. Demo will not run correctly.");
}
}, 1000);
}
function doAlert() {
var message = "This is an Alert dialog";
var title = "Attention!";
navigator.notification.alert(message, title);
}
</script>
</head>
<body onLoad="init();">
<h1>Cordova Tests</h1>
<div id="info">
<button onclick="doAlert();">Click Me</button>
</div>
</body>
</html>
Upvotes: 2