DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Frameworks
  4. Cordova (formerly PhoneGap) - Alert, Confirm, Vibrate and Beep in Windows Phone

Cordova (formerly PhoneGap) - Alert, Confirm, Vibrate and Beep in Windows Phone

Sumit Dutta user avatar by
Sumit Dutta
·
Sep. 04, 12 · Interview
Like (0)
Save
Tweet
Share
15.53K Views

Join the DZone community and get the full member experience.

Join For Free

In this article I will talk about the Notification feature of Cordova or PhoneGap in Window Phone. Notification has alert, confirm, beep and vibrate methods.

Let's write some code.

Step 1: Place below code in index.html located under www.

<!DOCTYPE html>
<html>
<head>
   <title>Getting Started Sample</title>
   <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
   <script type="text/javascript" charset="utf-8">
      var init = function init() {
         // Wait for Cordova to load
         document.addEventListener("deviceready", onDeviceReady, false);
         // Cordova is ready
         function onDeviceReady() {
         }
      };
      window.onload = init;
   </script>
</head>
<body>
   <div id="alertAction"></div>
   <div id="confirmAction"></div>
</body>
</html>

Step 2: Place below code inside onDeviceReady method to display alert message box.

function showAlert() {
   document.getElementById("alertAction").innerHTML = "Alert Button Pressed.";
}

navigator.notification.alert(
   'Alert Mesage!', 
   showAlert, 
   'Alert Title', 
   'Alert Button'
);

showAlert is callback method which triggers on click of the Alert Button.

Cordova or PhoneGap - Alert

On click of Alert Button of alert message box, showAlert callback will be executed.

PhoneGap or Cordova - alert

alert message box is asyncrhonous, it won't block the code execution.

 

 

Step 3: Now place below code inside onDeviceReady method to display confirm message box.

 

function showConfirm(buttonIndex) {
   document.getElementById("alertAction").innerHTML = "Button index is " + buttonIndex;
}

navigator.notification.confirm(
   'Confrim Message!', 
   showConfirm, 
   'Confirm Title', 
   'Button 1, Button 2, Button3'
);

 

showConfirm is callback method which triggers on click of button on confirm message box. It takes buttonIndex argument which is index of the pressed button in confirm message box.


Cordova or PhoneGap - Confirm


On click of second button (Button 2) of confirm message box, showConfirm method will be executed. In the below screen shot you will notice the the index is 2 because second button is pressed.


PhoneGap or Cordova-confirm

Like alert, confirm message box is also asyncrhonous, it won't block the code execution.

Step 4: Place below one line of code inside onDeviceReady method to make the device vibrate. It takes time as milliseconds, 1000 milliseconds equals 1 seconds.

 

navigator.notification.vibrate(500);

Step 5: Place below one line of code inside onDeviceReady method to play beep sound. It takes argument as number of times to beep.

 

navigator.notification.beep(3);

This ends the article of alert, confrim, vibrate and beep notification using Cordova or PhoneGap in Windows Phone.

 

Windows Phone Apache Cordova

Published at DZone with permission of Sumit Dutta, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Top Authentication Trends to Watch Out for in 2023
  • Spring Cloud: How To Deal With Microservice Configuration (Part 1)
  • Writing a Modern HTTP(S) Tunnel in Rust
  • Easy Smart Contract Debugging With Truffle’s Console.log

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: