You must Sign In to post a response.
  • Category: Webservices

    Create Push Notification

    How can i create a push notification in android and IOS.
    Send me a example code to test in my application.
  • #766112
    you first need to create a WebRequest, then assign content type, method and header to it, then you can use web response to push it
    I got following snippet, but I have not tested it.

    01.using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Net;
    using System.Text;
    using System.IO;
    protected void Button1_Click(object sender, EventArgs e)

    //Registration Id created by Android App i.e. DeviceId.
    string regId;
    regId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    //API Key created in Google project
    var applicationID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

    //Project ID created in Google project.
    var SENDER_ID = "xxxxxxxxxxxx";
    var varMessage = "Hello! How are you?";
    WebRequest tRequest;
    tRequest = WebRequest.Create("");
    tRequest.Method = "post";
    tRequest.ContentType = " application/x-www-form-urlencoded;charset=UTF-8";
    tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID));

    tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));

    string postDataToServer = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message="
    + varMessage + "&data.time=" + System.DateTime.Now.ToString() + "®istration_id=" + regId + "";

    Byte[] byteArray = Encoding.UTF8.GetBytes(postDataToServer);
    tRequest.ContentLength = byteArray.Length;

    Stream dataStream = tRequest.GetRequestStream();
    dataStream.Write(byteArray, 0, byteArray.Length);

    WebResponse tResponse = tRequest.GetResponse();

    dataStream = tResponse.GetResponseStream();

    StreamReader tReader = new StreamReader(dataStream);

    String sResponseFromServer = tReader.ReadToEnd();


    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #766114
    Do you want to send the notification to you Android or IOS application?
    For that you have to make http call from your web service / Web application.
    Just have one rest call in your IOS / Android get the data as JSON input based on the input you can create notification.

    No you can call that REST Call from your web application / Web service. It is nothing but simple Http client call.

    using (var client = new HttpClient())
    client.BaseAddress = new Uri("http://localhost:9000/");
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

    // New code:
    HttpResponseMessage response = await client.GetAsync("api/products/1");
    if (response.IsSuccessStatusCode)
    Product product = await response.Content.ReadAsAsync>Product>();
    Console.WriteLine("{0}\t${1}\t{2}", product.Name, product.Price, product.Category);

    By Nathan
    Direction is important than speed

  • #767273
    Hi Sumeet,

    You can use Push Sharp to manage Push notification for both IOS and android,

    Please refer below link for more reference

    You need to get Push notification Security certificate from App developer and include in your project

    This link provide you the implementation of push sharp to send notification for both IOS and Android

    public bool SendPushNotification(string deviceToken, string message)
    if (_pushNotificationApple != null)
    //your device Token and Message to be pushed.
    _pushNotificationApple.SendNotification(deviceToken, message);
    return true;

    Happy Coding

  • #767278
    If you are trying XAMARIN then this is the solution. XAMARIN allows you to code for IOS as well as Android at same time in a single project. You need to first install 'Push Notification Plugin for Xamarin' through Package Manager Console in VS and after that implement the 'IPushNotificationListener interface'.
    Please find the deo source code here:

  • Sign In to post your comments