Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Sending Notifications in Android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 58
    Comment on it

    For sending notifications to android phone first you need to register yourself in google developer console

    https://console.developers.google.com

    After doing registeration in that you need to generate an API key from it

     

    Code for GCM
    
    		    string GoogleAppID = gsm.NotificationGoogleAppId;
    
                        //Project ID created in Google project
                        var SENDER_ID = gsm.NotificationSenderId;
    
                        //Registration Id created by Android App i.e. DeviceId
                        string regID = deviceId.Trim();
    
                        WebRequest webRequest;
                        webRequest = WebRequest.Create("https://android.googleapis.com/gcm/send");
                        webRequest.Method = "post";
                        webRequest.ContentType = " application/x-www-form-urlencoded;charset=UTF-8";
                        webRequest.Headers.Add(string.Format("Authorization: key={0}", GoogleAppID));
                        webRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));
    
                        string postData = string.Format("collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message={0} &data.time={1} &data.badge={3} &data.type={4} &data.id={5} &data.sound={6}&registration_id={2}", message, DateTime.UtcNow, regID, badgeCount, type, id, "default");
    
                        Byte[] byteArray = Encoding.ASCII.GetBytes(postData);
    
                        webRequest.ContentLength = byteArray.Length;
    
                        Stream dataStream = webRequest.GetRequestStream();
                        dataStream.Write(byteArray, 0, byteArray.Length);
                        dataStream.Close();
    
                        WebResponse webResponse = webRequest.GetResponse();
    
                        dataStream = webResponse.GetResponseStream();
    
                        using (StreamReader streamReader = new StreamReader(dataStream))
                        {
                            String sResponseFromServer = streamReader.ReadToEnd();
                            streamReader.Close();
                            dataStream.Close();
                            webResponse.Close();
                        }

    This is the code where you have to pass the API key the Device UUID and the the Sender Id generated from the Google Console

     

     

     

    Android

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: