Newest Post

Integrating PushSharp In the WCF Restful Web Service to display Push Notifications in Apple, Android and Windows devices

| Monday, September 29, 2014
Read more »
Hello Folks, Today I will demonstrate the method of integrating the PushSharp library in WCF Restful Web Service to send the Push Notifications to Apple, Android and Windows devices.

This library and its documentation is available on the GitHub at following link


Create a new WCF web service in the Visual Studio(Here I am using Visual Studio 2012). After creating the Web Service, Go to Tools-> NuGet Package Manager -> Manage NuGet Packages for Solution as shown in following image.

In the Package Manager, Search "PushSharp" 

After installing PushSharp NuGet Package, following dlls will be added in the bin folder of the solution. 

Next are the lines of the code which are used to send the notifications from the web service. Please consider following is the minimalist code required to send notifications to devices. For additional functionality, please go through the samples given in the GitHub library of PushSharp.

For Sending Push Notifications to the Android device.

 public void SendAdnoirdPush(string APIKey, string DeviceID, string Message)  
     var push = new PushBroker();  
     push.RegisterGcmService(new GcmPushChannelSettings(APIKey));  
     push.QueueNotification(new GcmNotification().ForDeviceRegistrationId(DeviceID)  
             .WithJson("{\"alert\":\"" + Message + "\",\"badge\":7,\"sound\":\"sound.caf\"}"));  

APIKey of the App can be obtained from the Google Developer Console.
DeviceId of the device using the App.
Message to be displayed in the Notification.

For Sending Push Notifications to the iOS device.

 public void SendiOSPush(string DeviceID, string Message, string sound)  
     var push = new PushBroker();  
     var appleCert = File.ReadAllBytes(new DirectoryInfo(HostingEnvironment.ApplicationPhysicalPath) + "/pushNotificatio.p12");  
     push.RegisterAppleService(new ApplePushChannelSettings(true, appleCert, "CertificatePassword"));  
     push.QueueNotification(new AppleNotification()  
     //.WithSound("sound.caf")); //default  

DeviceId of the device using the App.
Message to be displayed in the Notification
sound to be played with Notification

For implementing the iOS Notifications, a signed certificate is required to be generated from the Developer Console. That certificate is copied in the system and Path is given as in the method above. 
Please be careful while mapping the path of the certificate. The certificate is different for sandbox and production
RegisterAppleService requires the certificate password. 

For Sending Push Notifications to the Windows phone.

 public void SendWindowsPhonePush(string ChannelUri, string pageName, string Header, string Message)  
     var push = new PushBroker();  
     push.QueueNotification(new WindowsPhoneToastNotification()  
     .ForEndpointUri(new Uri(ChannelUri))  
     .WithNavigatePath("/" + pageName)  

ChannelUri is the unique identifier for each device using the App
pageName to navigate to when notification is clicked
Header to be displayed in the Notification Header
Message to be displayed in the Notification Message

and voila!!!! DONE

Above methods can also be combined into one method to send notification to all types of devices., also If notifications are to be sent to multiple devices of same OS, then a "for" loop can be traversed as per the requirement for each method.

Display a Toast Message in Android

| Wednesday, September 24, 2014
Read more »
Toast is used to display the message in small popup over the background activity. This message disappears after some time as per the duration specified in the Toast call.

Following is the syntax used for displaying the Toast Message on Android device.

 Toast.makeText(context, text, duration).show();  

This method takes 3 parameters

  1. Application Context
  2. Text Message
  3. Duration of the Toast


 Toast.makeText(login.this, "Username required", Toast.LENGTH_LONG).show();  

Display a Toast Message in Android

Posted by : Pooja
Date :Wednesday, September 24, 2014
With 0comments
Tag :
Next Prev