-1

I have installed Notification plugin like this:

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

Then I have added to the config.xml in /www/ folder:

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

And I have tried to test the plugin like this in my index.html:

    document.addEventListener("deviceready", onDeviceReady, true);

    function onDeviceReady() {
        alert('Device ready');

        var beep = function(){
           try{
               if(navigator != null){
                   navigator.notification.alert("2");
               }else{
                alert(navigator);
               }
           }catch(e){
               alert("Alert failed: " + e.message);
           }
        }

        beep();


    }

But I always get "Alert failed" as the message that the navigator.notification is undefined.

I am using phonegap 3.3.0-0.19.6 and I build the project with phonegap local build android

What am I missing?

Aleks
  • 4,866
  • 3
  • 38
  • 69
  • No other messages from the logcat? For example, the official documentation says that you should add a specific permission ` ` in your Manifest file. Probably this is only related to the vibration, but actually there is nothing in the doc that says that this permission is not mandatory. – Lorenzo S Jun 12 '14 at 14:43
  • Thanks lorenzo, but I haven't mentioned `vibration` word anywhere :) I am only interested in displaying a custom alert notifications and not to use standard black ones that appear on Android if I use `alert("This is error message")` – Aleks Jun 12 '14 at 14:51
  • I love downvotes without comments :) – Aleks Jun 19 '14 at 12:43

4 Answers4

3

I think you should use a different url: phonegap local plugin add https://github.com/apache/cordova-plugin-dialogs

Or better still, use the Cordova CLI and do: cordova plugin add org.apache.cordova.dialogs

And then cordova prepare

That should take care of changing the config.xml etc for you.

Eddy Verbruggen
  • 3,550
  • 1
  • 15
  • 27
  • I think those two urls will result in the same plugin. I will check. But as for the suggestion of using a Cordova CLI, I don't think it is wise to mix `phonegap` and `cordova` adding a plugin in the same project. The phonegap command will do the same – Aleks Jun 18 '14 at 07:02
  • Well, I wouldn't want for the bounty points to go wasted, I am going to award you the points. But will see what was the final answer to my question, and post if I find the cause of the 'error'. Thanks – Aleks Jun 20 '14 at 10:21
1

I am using phonegap cloud build, and for me adding following line to the phonegap config.xml fixed the problem

<gap:plugin name="org.apache.cordova.dialogs" />
Asanka
  • 429
  • 3
  • 10
0

Check /assets/www/cordova_plugins.js file and see if it's reference to notification plugin is such as this,

{
        "file": "plugins/org.apache.cordova.dialogs/www/notification.js",
        "id": "org.apache.cordova.dialogs.notification",
        "merges": [
            "navigator.notification"
        ]
    },
    {
        "file": "plugins/org.apache.cordova.dialogs/www/android/notification.js",
        "id": "org.apache.cordova.dialogs.notification_android",
        "merges": [
            "navigator.notification"
        ]
    },

Also check /assets/www/plugins/org.apache.cordova.dialogs/www folder contents. is it same as the referenced by in your cordova_plugins.js file?

Asanka Indrajith
  • 353
  • 3
  • 13
0

I had the same issue, and this is what you have to do in order to get it work:

Use cordova cli:

 cordova plugin add org.apache.cordova.dialogs

cordova build

Then, cordova build is not always adding the right lines to the config.xml - So we have to change it to the following: (in app/res/xml/config.xml - not www folder)

<feature name="Notification">
    <param name="android-package" value="org.apache.cordova.dialogs.Notification" />
</feature>
griffon vulture
  • 6,594
  • 6
  • 36
  • 57
  • thanks, but I am using phonegap and not cordova and all the notifications seems to be installed properly. Should I use instead of your command , should I use `local phonegap plugin add org.apache.cordova.dialogs` – Aleks Jun 19 '14 at 09:37
  • No, but: A.take care at my second comment - have you the right lines on - app/res/xml/config.xml? B. For me cordova solved some problems, so consider using of it. – griffon vulture Jun 19 '14 at 09:42
  • thanks, but: A. Look at my question :) Did you meant adding those lines to the `config.xml` ? Also, I have to note, changing anything outside www/config.xml is only a temporary solution. Consider this post http://stackoverflow.com/questions/19112436/should-a-phonegap-plugin-be-declared-in-the-config-xml-file and also I shouldn't mix phonegap and cordova, that is as far my sanity tells me :) (At the end I end up answering to some other posts :/ ) – Aleks Jun 19 '14 at 10:03