I am using PushBots plugin in my Phonegap application for android phones. I need to get the device registration id from google cloud messaging server to send user specific push notification. I am using PHP and mySQL in back-end. Basically I need to save the device registration id to mysql db once the device is ready. Please help me to get a solution.
Asked
Active
Viewed 1,037 times
0
-
What you have tried?show your code – shamon shamsudeen Aug 17 '15 at 04:35
-
Did you solve this? I am trying to do the same thing and the answer here didn't work for me. – Marty.H Sep 16 '15 at 00:20
1 Answers
0
First get the device token and store it to the database,and later it can be used for sending push-notification.
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady(){
//setting up for android
if(PushbotsPlugin.isAndroid()){
PushbotsPlugin.initializeAndroid("PUSHBOTS_APP_ID", "GCM_SENDER_ID");
}
//get the device token
PushbotsPlugin.getToken(function(token){
console.log(token);
//setup an ajax request to store the device token
$.ajax({
url:'register.php',
method:"POST",
data:{token :token},
success:function(data){
console.log("from server"+data);
},
error:function(err){
console.log("error"+err);
}
});
});
}
register.php
<?php
$token=$_POST['token'];
//setup database query for store the token
if($query==true){
echo 'success';
}else{
echo 'error';
}
?>
Also replace PUSH_BOT_APP_ID
and GCM_SENDER_ID
with your values

shamon shamsudeen
- 5,466
- 17
- 64
- 129
-
Hi Shammon, I am not able to get the token. I tried to display the token by document.getElementById("MyDiv").innerHTML=token; but still it not working. Please advise. – Ganesh V.V. Aug 20 '15 at 02:53