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"
});
}
}
function onNotification(e) {
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 ){
$.ajax({
url:'common_db.php',
data:'action='+'registergcm'+'&id='+e.regid,
success:function(data){
}
});
}
break;
case 'message':
if(e.foreground){
var soundfile = e.soundname || e.payload.sound;
var my_media = new Media("android/assets/www/"+ soundfile);
my_media.play();
}else{
}
break;
case 'error':
console.log("Error"+e.msg);
break;
default:
console.log("An unknown event");
return;
}
}
in my php file
$reg_id=$_GET['id'];
$sql=mysql_query("select reg_id from tbl_insert_ids where id='$reg_id'");
if(mysql_num_rows($sql)==1){
echo '';
}else{
$sql=mysql_query("insert into tbl_insert_ids values('','$reg_id')");
if($sql){
echo 'Success';
}else{
echo 'Error'
}
}
. . , .