用C#asp.net给null作为在Android设备通知GCM推送通知 [英] GCM push notification with C# asp.net giving null as notification in android devices

查看:223
本文介绍了用C#asp.net给null作为在Android设备通知GCM推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建在C#中的一类具有发送推送通知,Android的使用GCM的方法。该方法是运作良好,也给应对来自谷歌的成功。但在Android模拟器通知即将为空。
这里是code我使用,

I am creating a class in C# which has a method to send push notification in android using GCM. The method is working well and also giving response from google as success. But in the android emulator the notification is coming as null. Here is the code I am using,

public void NotifyTest(string regId)
    {
        var applicationID = "AIza*************"; 

        var SENDER_ID = "xxxxxxxxxx"; 
        var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://android.googleapis.com/gcm/send");
        httpWebRequest.ContentType = "application/json";
        httpWebRequest.Method = "POST";
        httpWebRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID));
        httpWebRequest.Headers.Add(string.Format("Sender: key={0}", SENDER_ID));
        using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
        {
            string json = "{\"registration_ids\":[\""+ regId +"\"]," +
                        "\"data\": { \"score\" : \"1234\"}}";
            Console.WriteLine(json);
            streamWriter.Write(json);
            streamWriter.Flush();
            streamWriter.Close();

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                Console.WriteLine(result);
            }
        }
    }

在code工作没有任何错误,过于返回从谷歌的回应。请让我知道的建议。

The code is working without any errors and returning the response from Google too. Please let me know the suggestions.

推荐答案

在Android的的onMessage(在GCMIntent服务)写folowin行

In Android OnMessage(in GCMIntent service) write folowin line

  String message = intent.getStringExtra("score");

快乐Coading:)

Happy Coading:)

这篇关于用C#asp.net给null作为在Android设备通知GCM推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆