Ashoka Mondal
Ashoka Mondal

Reputation: 1171

Notification.alert is not working in phonegap build 3.1.0

I am creating a phonegap application. I have used notification.alert to show messages. Before updation of phonegap 3.1.0 the notification.clert was working fine. As i have done about 5 app using phonegap 2.9.0. In every app i have used notification.alert from this

Now i have build my working project on 28th jan 2014, It is showing only 3 apps (Iphone, android and windows) can be done using phonegap. I am creating for IOS and Android. Everything is working fine except alert. Is there any problem in new phonegap? Is there any new method or command to show alert messages?

Please help me why it is not working. If you have any other idea then please help me.

Upvotes: 2

Views: 10451

Answers (1)

Radu Turtoi
Radu Turtoi

Reputation: 189

As of version 3.0, Phonegap/Cordova implements device-level APIs as plugins so you have to include this in your config.xml found in the www folder

<gap:plugin name="org.apache.cordova.dialogs" />

or add it manually from the phonegap CLI like this:

 $ cordova plugin add cordova-plugin-dialogs
 $ cordova plugin ls
    [ 'org.apache.cordova.dialogs' ]
 $ cordova plugin rm org.apache.cordova.dialogs

After you include it you can use like this

<!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
    }

    // alert dialog dismissed
        function alertDismissed() {
            // do something
        }

    // Show a custom alertDismissed
    //
    function showAlert() {
        navigator.notification.alert(
            'You are the winner!',  // message
            alertDismissed,         // callback
            'Game Over',            // title
            'Done'                  // buttonName
        );
    }

    </script>
  </head>
  <body>
    <p><a href="#" onclick="showAlert(); return false;">Show Alert</a></p>
  </body>
</html>

You can research further here . Happy coding!

Upvotes: 9

Related Questions