Using native alerts and cofirmations of mobile using Cordova

The PhoneGap/Cordova framework allows you to display native dialog box of the device, which allows you to use say custom title and better control on number of buttons on the dialog box. In addition to that it also allows you to beep or vibrate the device(Both beep and vibrate feature dont seem to work in the Android emulator). I wanted to try these features so i built this sample application, which allows you to play with different notifications. This is how the native alert box looks like This is how the native confirmation box looks like I followed these steps to build Android PhoneGap application
  1. I followed the instructions in Getting Started with Android to build application that points to index.html inside the application, i tried it once to make sure that it works
  2. Then i used the following index.html code
    
    <!DOCTYPE html>
    <html>
      <head>
        <title>Google Map Example</title>
      <meta name="viewport" content="width=device-width, 
      initialscale=1.0, user-scalable=no"></meta>
        <script type="text/javascript" charset="utf-8" 
    src="cordova-1.7.0.js"></script>
        <script type="text/javascript" charset="utf-8">
        function alertDismissed() {
            console.log("Inside alertDismissed");
        }
        function onConfirm(){
          console.log("Inside onConfirmation");
        }
        function showAlert() {
            navigator.notification.alert(
                'Sample native alert message',  
                alertDismissed,         
                'Sample native alert title',            
                'alert'                  
            );
        }
        function showConfirmation(){
          navigator.notification.confirm(
                  'Sample native confirmation',  
                  onConfirm,              
                  'Sample confirmation title',            
                  'Confirm'          
              );
        }
        function playBeep() {
            navigator.notification.beep(3);
        }
        function vibrate() {
            navigator.notification.vibrate(2000);
        }
        </script>
      </head>
      <body >
        <ul>
          <li><a href="#" onclick="alert('Browser alert'); 
    return false;">Show browser Alert</a></li>
          <li><a href="#" onclick="showConfirmation(); 
    return false;">Show Confirmation</a></li>
          <li><a href="#" onclick="showAlert(); 
    return false;">Show Alert</a></li>
          <li><a href="#" onclick="playBeep(); 
    return false;">Play Beep</a></li>
          <li><a href="#" onclick="vibrate(); 
    return false;">Vibrate</a></li>
        </ul>
         <p></p>
      </body>
    </html>
    
    The HTML of the page shows 5 different links each pointing to one JavaScript function. Each of the functions uses Phone Gap native feature to display native dialog boxes.

1 comment:

Unknown said...

Nice post and great content.
Avast Customer Support is here to help you out with the whole procedure to Download Avast Antivirus online, We not only fix your Avast Support related issues but will guide with how to get started with your new Avast product once it gets installed successfully. We at Avast Tech Support provides service to protect your PC from potential online threats and external attacks like viruses, Trojans, malwares, spywares and phishing scams. And Avast Refund. Call on our Avast Phone Number

Gmail Customer service is a third party technical support service for Gmail users when they face any technical issue or error in their Gmail account. Our Gmail Customer Support team solves issues like forgot Gmail account password, Gmail configuration or Sync issues, recover deleted emails and many more. Toll Free number (800) 986-9271

How you install or reinstall Office 365 or Office 2016 depends on whether your Office product is part of an Office for home or Office for business plan. If you're not sure what you have, see what office com setup products are included in each plan and then follow the steps for your product. The steps below also apply if you're installing a single, stand-alone Office application such as Access 2016 or Visio 2016. Need Help with office setup Enter Product Key? Call 1-800-000-0000 Toll Free
Norton Tech Support is a third party service provider and not in any way associated with Norton or any of its partner companies. We offer support for Norton products and sell subscription based additional warranty on computer and other peripheral devices. Call our Toll Free number 1 855 966 3855
Other Services
Norton Toll Free , Office-Setup , office.com/setup.