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
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.
 
 
 

About Author

Author Image
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.

Request for Proposal

Name is required

Comment is required

Sending message..