using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Net;
using System.IO;
namespace AndroidPushNOtifcation
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SendCommandToAndroidPhone("APA91bHTWs7e0t57Y3ymbM2VVZakZ7vUzmXa8BJZdGAr06HUV5mBMbgorZOKlAQsMCmlXqXh1rt9IugPqi6eZ6cwfvZR_oY2YM9YzQnR45jXOrR5gK4U8oObnDjnObJ6d0PGMDX1MqFj_ey6_HKOXjty28T4H6YY7Q", "Second Test");
}
public string SendCommandToAndroidPhone(String deviceID, string Mesaj)
{
String GoogleAppID = "AIzaSyCwElHkNZpY6P2RkIsbMQWxI1OgQnuv8_g";
WebRequest tRequest;
tRequest = WebRequest.Create("https://android.googleapis.com/gcm/send");
tRequest.Method = "post";
tRequest.ContentType = "application/x-www-form-urlencoded";
tRequest.Headers.Add(string.Format("Authorization: key={0}", GoogleAppID));
String collaspeKey = Guid.NewGuid().ToString("n");
String postData = string.Format("registration_id={0}&data.payload={1}&collapse_key={2}", deviceID, Mesaj, collaspeKey);
Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
tRequest.ContentLength = byteArray.Length;
try
{
Stream dataStream = tRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse tResponse = tRequest.GetResponse();
dataStream = tResponse.GetResponseStream();
StreamReader tReader = new StreamReader(dataStream);
String sResponseFromServer = tReader.ReadToEnd();
tReader.Close();
dataStream.Close();
tResponse.Close();
return "Android : " + sResponseFromServer;
}
catch (Exception ex)
{
return "Android : " + ex.Message;
}
}
}
}
此代码适用于单个设备 ID 但在多播发送通知中失败请帮助我如何在 android 中发送多播通知。我已经尝试了很多,并尝试找到我在 Java 代码中找到的如何发送多播发送通知,但不是在 c# 代码中,请帮助我如何更改它多播。