Android Push Notification via Azure Server
Posted By : Akhil Dhiman | 29-May-2015
Here i will show you how to send push notification to android device via azure server. For this we need to install cordova plugin name "cordova-plugin-azure-notificationhub". You can check this plugin from below link.
To add this plugin in your project follow the following procedure :
Download the plugin from above link and using terminal go in your project directory, from inside your Cordova project you have to enter the following command.
cordova plugin add "path to plugin"
Below is the method to register your device to azure server.
var connectionString = "Endpoint=sb://xxxxx.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=[sha key]",
notificationHubPath = "hub name";
var senderId = "275450510999";
var hub = new WindowsAzure.Messaging.NotificationHub(notificationHubPath, connectionString, senderId);
hub.registerApplicationAsync().then(function (result) {
alert("Registration successful: " + result.registrationId);
console.log("Registration successful: " + result.registrationId);
baseUtils.setData("registrationId", result.registrationId);
},function(error){
alert("Registration failed: " + error);
});
connectionString, notificationHubPath will be provided from server.
you will get your senderId from google developer account
you will get your senderId from google developer account
Below is the method to receive push notification from server.
hub.onPushNotificationReceived = function (msg) {
console.log("Push Notification received: " + msg);
};
Now you can send push notification from server and you will receive notification on mobile.
Request for Proposal
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Akhil Dhiman
Akhil is an iPhone and Android application developer with experience in PhoneGap and Swift(Native iOS). Akhil has good experience working with JavaScript, jQuery and Underscore as well.