Only getting the string “OK” and not the device / registration ID from the pushto cordova plugin using Android

I installed the push notification plugin and call the register method, but it returns the string “OK” instead of the device identifier. How to get a registered device identifier?

   $window.plugins.pushNotification.register(
          function (result) {
            q.resolve(result); //this always just returns the string "OK", how do I get the device ID?
          },
          function (error) {
            console.log(error);
            q.reject(error);
          },
          config);

        return q.promise;
      },

e.regid is null taken from this example

// Android and Amazon Fire OS
function onNotification(e) {
    $("#app-status-ul").append('<li>EVENT -> RECEIVED:' + e.event + '</li>');

    switch( e.event )
    {
    case 'registered':
        if ( e.regid.length > 0 )
        {
            $("#app-status-ul").append('<li>REGISTERED -> REGID:' + e.regid + "</li>");
            // Your GCM push server needs to know the regID before it can push to this device
            // here is where you might want to send it the regID for later use.
            console.log("regID = " + e.regid);
        }
    break;

    case 'message':
        // if this flag is set, this noti
+4
source share
3 answers

push. register iOS , Android . Android ecb push-, .

,

if ( device.platform == 'android' || device.platform == 'Android' || device.platform == "amazon-fireos" ){
    pushNotification.register(
    successHandler,
    errorHandler,
    {
        "senderID":"replace_with_sender_id",
        "ecb":"onNotification"
    });
} 

"ecb" "onNotification", sucess.

onNotification . onNotification Android, .

+5

android ecb, . , ( , ):

var GOOGLE_SENDER_ID = '/* replace with yours */';
var deferred;

function registerWithGCMServer() {
    deferred = $.Deferred();

    window.plugins.pushNotification.register(
        function() {
            //It will be resolved in 'window.onAndroidNotification'
            //when the device is registered and the token is gotten
            //our rejected if the timeout is reached
        },
        function() {
            deferred.reject('Error registering.');
        }, {
            senderID: GOOGLE_SENDER_ID,
            ecb: 'window.onAndroidNotification'
        });

    setTimeout(function() {
        if(deferred.state() === 'pending') {
            deferred.reject('Error registering (timeout).');
        }
    }, 10000); //10s

    return deferred.promise();
}

window.onAndroidNotification = function(e) {
    if(e.event == 'registered') {
        deferred.resolve(e.regid);
    } else if(e.event == 'message') {
        onMessageRecived.call(null, e.message);
    }
};

:

registerWithGCMServer()
    .then(function(deviceToken) {
        console.log('Device registered and its token is ' + deviceToken);
    })
    .fail(function(e) {
        console.error(e);
    });

function onMessageRecived(message) {
    console.log('Push message received: ' + message);
}
+1

. ( id dev) . gcm.

Samsung: , push-. , -, , .

Finally, be sure to include the “message” and “header” in the payload data if you want the notification to display correctly on the taskbar.

0
source

All Articles