Bob
Bob

Reputation: 10775

Apache Cordova 3 plugins not working

I am absolutely new to Apache Cordova and trying to use Cordova plugins. I added some plugins (Device, Notification) and see the in plugins list. Also, I am developing only Android app. enter image description here

Basic examples that I am copying from the documentation page are not working.

    $(".buttons button").click(function() {
        showAlert();
    });

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

or this

<input type="text" class="form-control" id="expression" placeholder="Expression">

var phoneName = device.name;
$("#expression").val(phoneName);

Can anybody explain what I am doing wrong?

Upvotes: 0

Views: 55

Answers (1)

Nitish Dhar
Nitish Dhar

Reputation: 2312

Follow these steps to use any specific plugin in Cordova 3 -

Assuming your project directory is myApp & you want to use notification/dialog plugin -

cd myApp
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git

Once you do this, cordova fetches the dialogs plugin & adds it to your plugins directory. Now you need to specificy in your code that you want to use this plugin.

Open to your android config file -

myApp/res/xml/config.xml

And add the following line to it -

<feature name="Notification">
    <param name="android-package" value="org.apache.cordova.Notification" />
</feature>

Now setup your alert function, don't forget to define the callback function, I don't see the same in your given code -

function alertDismissed() {
   // do something
}

navigator.notification.alert(
    'You are the winner!',  // message
    alertDismissed,         // callback
    'Game Over',            // title
    'Done'                  // buttonName
);

Now run a build

cordova build android

You should be able to use the dialog now.

More Details

https://cordova.apache.org/docs/en/3.0.0/cordova_notification_notification.md.html

Upvotes: 1

Related Questions