krishwader
krishwader

Reputation: 11381

phonegap notification methods still use webview alert

I'm using phonegap CLI to check if default notifications work. I already added the notification plugin and I got this output when I ran :

D:\PhoneGap\apps\alerttest> cordova plugins ls

['org.apache.cordova.dialogs', 'org.apache.cordova.vibration' ]

This is how my JS looks like:

document.addEventListener('deviceready', function () {
    if (navigator.notification) {
        //Im trying to overwrite the default alert & confirm here if navigator.notification is defined 
        window.alert = function (title, message, button, onFinish) {
            navigator.notification.alert(message, onFinish, title, button);
        };

        window.confirm = function (title, message, buttons, onFinish) {
            var onDone = function (btnIndex) {
                switch (btnIndex) {
                    case 0:
                        break;
                    case 1:
                        onFinish(true);
                        break;
                    case 2:
                        onFinish(false);
                        break;
                }
            }
            navigator.notification.confirm(message, onDone, title, buttons);
        }
    }
    else {
        var $alertBox = $(".alert-box.warning");
        $alertBox.html("No notification support :(");
        $alertBox.show();
    }
});

When I use these functions,

alert("Alert", "I was clicked.", "Yes, I got it!", null);
confirm("Confirm", "2 + 2 = 4. Yes or no?", ["Yes", "No"], onDone);

I get something like these :

for alertenter image description here

Which is still the WebView alert. I was expecting something like this:

enter image description here

What am I doing wrong here?

Using PhoneGap CLI, version number : 3.1.0-0.2.0

Also, Im using Android Jellybean (4.1.2) to check this feature

Upvotes: 1

Views: 1509

Answers (2)

krishwader
krishwader

Reputation: 11381

Yes I got it! I had to change the android:theme in the manifest file from "@*android:style/Theme.Black.NoTitleBar" to "@*android:style/Theme.DeviceDefault" to viola, it works! Thanks Divesh Salian for giving me a clue about this!

Upvotes: 4

flauntster
flauntster

Reputation: 2016

make sure this is in your config.xml -

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

Upvotes: 0

Related Questions