[英]How to Setup a Push Notification(or GCM) mechanism in android while Back-end uses ASP.NET
后端使用ASP.NET時如何在android中設置推送通知(或GCM)機制
我想設置一個應用程序GCM,但后端在ASP.net中,請盡可能參考完整指南。
服務器端和android端
為了部分回答這個問題,服務器端可以用C#實現。 消息格式和一般方法記錄在以下鏈接中。
http://developer.android.com/google/gcm/server.html
https://developer.android.com/google/gcm/http.html
https://developers.google.com/cloud-messaging/server-ref#table1
話雖如此,實際的推送消息可以如下發送。
var iReq = WebRequest.Create("https://android.googleapis.com/gcm/send");
iReq.Method = "post";
iReq.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
iReq.Headers.Add(String.Format("Authorization: key={0}", Key));
string iMsg;
// iMsg must be filled with the actual data to be sent
// and understood by the client
var PostData = Uri.EscapeUriString(PostData);
var byteArr = Encoding.UTF8.GetBytes(PostData);
iReq.ContentLength = byteArray.Length;
var DataStream = iReq.GetRequestStream();
DataStream.Write(byteArray, 0, byteArray.Length);
DataStream.Close();
string ServerResponse; // will contain the response to examine
HttpStatusCode StatusCode;
using (var iRes = iReq.GetResponse())
{
using (var iReader = new StreamReader(iRes.GetResponseStream()))
{
ServerResponse = iReader.ReadToEnd();
}
StatusCode = (iResponse as HttpWebResponse).StatusCode;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.