Reputation: 1759
Created UI using Angular and Ionic, and wrapper usign Phonegap, How can I have pushnotification in Android implemented. Is there any effective and accurate library in Phonegap for Pushnotification Implemented.
Already using https://github.com/phonegap-build/PushPlugin, but getting some issues, like push notififcation not received, some time all notification coming at once.
Upvotes: 0
Views: 1001
Reputation: 4811
use the following plugin
cordova plugin add phonegap-plugin-push --variable SENDER_ID="XXXXXXX"
replace the xxxxxx with your sender id
n your javascript add the following code for registering to GCM server it will give you a GCM id
var push = PushNotification.init({
android: {
senderID: "XXXXXXXX" //add your sender id here
},
ios: {
alert: "true",
badge: "true",
sound: "true"
},
windows: {}
});
push.on('registration', function(data) {
consol.log(data.registrationId); //this function give registration id from the GCM server if you dont want to see it please comment it
document.getElementById("gcm_id").value= data.registrationId; //showing registration id in our app. If it shows our registration process is suscess
//$("#gcm_id").val(data.registrationId); if you are using jquery
});
Send a message using GCM HTTP connection server protocol:
https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=YOUR SERVER KEY
{
"to": "GCM ID",
"data": {
"message": "This is a GCM Topic Message!",
}
}
for more details..
http://phonegaptut.com/2016/05/31/how-to-send-push-notifications-in-phonegap-application/
Upvotes: 2
Reputation: 81
As Push Notification is a native feature, so to integrate Push in PhoneGap Android application you have to make a plugin that will communicate with Android Native code.
You can go through with Sample application available on Git Hub. Please also follow the necessary steps require for it mentioned in ReadME file.
Upvotes: 1
Reputation: 6973
You should be using ngCordova's Push Plugin for this.
From the docs:
Allows your application to receive push notifications. To receive notifications in your controllers or services, listen for pushNotificationReceived event.
Upvotes: 1
Reputation: 8503
I was having the same problem lately, using Ionic and Cordova (not Phonegap, but should work the same). I ended up using this library for local push notifications https://github.com/Wizcorp/phonegap-plugin-localNotifications
They worked pretty well except the PN would not start the app on Android, but I opened a pull request with a fix for that. If you encounter the same problem, you might also use my fork of this plugin which has this fix already included.
Upvotes: 1