PhoneGap Build Push Notification (Android)

后端 未结 2 2022
星月不相逢
星月不相逢 2020-12-16 21:54

I am having trouble receiving any type of callback for the push notifications plugin for phonegap build, I have included the plugin inside config.xml.

I have signed

相关标签:
2条回答
  • 2020-12-16 22:50

    Try this push notification code -

    var pushNotification;
    
    document.addEventListener('deviceready', onDeviceReady, true);
    
    function onDeviceReady() {
    
       try {
           pushNotification = window.plugins.pushNotification;
           if (device.platform == 'android' || device.platform == 'Android') {
               pushNotification.register(successHandler, errorHandler, { "senderID": "123456789", "ecb": "onNotificationGCM" });    // required!
              }
          else {
              pushNotification.register(tokenHandler, errorHandler, { "badge": "true", "sound": "true", "alert": "true", "ecb": "onNotificationAPN" }); // required!
              }
          }  
        catch (err) {
            txt = "There was an error on this page.\n\n";
            txt += "Error description: " + err.message + "\n\n";
            alert(txt);
         }
       };
    
    // handle GCM notifications for Android
    function onNotificationGCM(e) {
        switch (e.event) {
            case 'registered':
                if (e.regid.length > 0) {
                    alert(e.regid);
                    storeToken(e.regid);
                }
                break;
    
            case 'message':
                if (e.foreground) {
                    var my_media = new Media("beep.wav");
                    my_media.play();
                }
                else {  
                  // otherwise we were launched because the user touched a notification in the notification tray.
                }
    
                break;
    
           case 'error':
               break;
           default:
              break;
        }
    }
    

    Refer Link

    Refer Devgirl's Weblog

    0 讨论(0)
  • 2020-12-16 22:56

    I think I've found the solution.

    I was passing an integer instead of a string for the property senderID in the object

    Doesnt work

    pushNotification.register( 
        function(){alert('Push: win');}, // NOT called
        function(){alert('Push: Error');},  // NOT called
        { senderID: 123456789, ecb: "app.push_android" }
    );
    

    DOES work

    pushNotification.register( 
        function(){alert('Push: win');}, // called
        function(){alert('Push: Error');},  // called
        { senderID: "123456789", ecb: "app.push_android" }
    );
    
    0 讨论(0)
提交回复
热议问题