Pashtotifikatsiya in identifiers of several orders Phongap android of the same device

I am trying to embed a push notification using Phonegap in android using a push plugin. Everything works fine, but the problem is with device IDs. Every time the application launches it, sends an ajax request to the server to store registration identifiers later. can be used to send notifications to the device. On the server side, I also checked if the device is registered. The problem is in the same device as other registration identifiers are generated, so server-side verification is not performed (since the same device has different register identifiers). this is my push.js file

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

var pushNotification;

function onDeviceReady() {
    pushNotification = window.plugins.pushNotification;
    setupNotificationsForandroid();
}

function setupNotificationsForandroid() {

    if ( device.platform == 'android' || device.platform == 'Android' || device.platform == "amazon-fireos" ){

        pushNotification.register(
        successHandler,
        errorHandler,
        {
            "senderID":"527612045331",
            "ecb":"onNotification"
        });
    } else {
        pushNotification.register(
        tokenHandler,
        errorHandler,
        {
            "badge":"true",
            "sound":"true",
            "alert":"true",
            "ecb":"onNotificationAPN"
        });
    }
}

// Android
function onNotification(e) {
    switch( e.event )
    {
    case 'registered':
          if ( e.regid.length > 0 ){
           //set up the server call for storing registraion ids
             $.ajax({
                     url:'common_db.php',
                     data:'action='+'registergcm'+'&id='+e.regid,
                     success:function(data){

                            }
                     });
          }

    break;

    case 'message':
            // if this flag is set, this notification happened while we were in the foreground.
        if(e.foreground){
            var soundfile = e.soundname || e.payload.sound;
            var my_media = new Media("android/assets/www/"+ soundfile);
            my_media.play();
        }else{
           // otherwise we were launched because the user touched a notification in the notification tray.
        }


        break;

    case 'error':
           console.log("Error"+e.msg);
           break;

    default:
        console.log("An unknown event");
        return;
  }
}

in my php file

    //get id from application
     $reg_id=$_GET['id'];
//this check fails beacuse of differnt registration ids from the device
     $sql=mysql_query("select reg_id from tbl_insert_ids where id='$reg_id'");
     //check if already registerd
     if(mysql_num_rows($sql)==1){
       //do nothing
       echo '';

     }else{
       //store the registration ids in database table.
       $sql=mysql_query("insert into tbl_insert_ids values('','$reg_id')");
       if($sql){
         echo 'Success';
       }else{
         echo 'Error'
       }

     }

. . , .

0

All Articles