问题描述
我已经建立在谷歌云消息的应用(GCM)
他们给我:
I've Create An Application in Google Cloud Messaging (GCM)And they Give Me :
- 发件人ID
- API-KEY
- SENDER-ID
- API-KEY
我已经创建一个Android应用程序,客户可以用来注册他们的设备结果
云..(和它的确定)。
I've Create An Android Application that Clients Can Used To Register their Devices
to the cloud .. (And It's OK).
现在我要推休息设备的通知,如果任何用户使用数据我的Android应用程序改变的东西(SQL Server数据库)。
Now I want to Push A notification to Rest Of Devices if Any User Using My Android Application Change Something in the data (SQL SERVER DATABASE) .
我发现这code ...
I found This Code ...
private string SendGCMNotification(string apiKey, string postData, string postDataContentType = "application/json")
{
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateServerCertificate);
//
// MESSAGE CONTENT
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
//
// CREATE REQUEST
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("https://android.googleapis.com/gcm/send");
Request.Method = "POST";
Request.KeepAlive = false;
Request.ContentType = postDataContentType;
Request.Headers.Add(string.Format("Authorization: key={0}", apiKey));
Request.ContentLength = byteArray.Length;
Stream dataStream = Request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
//
// SEND MESSAGE
try
{
WebResponse Response = Request.GetResponse();
HttpStatusCode ResponseCode = ((HttpWebResponse)Response).StatusCode;
if (ResponseCode.Equals(HttpStatusCode.Unauthorized) || ResponseCode.Equals(HttpStatusCode.Forbidden))
{
var text = "Unauthorized - need new token";
}
else if (!ResponseCode.Equals(HttpStatusCode.OK))
{
var text = "Response from web service isn't OK";
}
StreamReader Reader = new StreamReader(Response.GetResponseStream());
string responseLine = Reader.ReadToEnd();
Reader.Close();
return responseLine;
}
catch (Exception e)
{
}
return "error";
}
public static bool ValidateServerCertificate(
object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
return true;
}
不过,当我需要执行的方法(它要求我给它浏览器APIKey
的参数)
string deviceId = "APA91bHsQUsnYLHSFkmmJE8AgXEU--_nqPOJ5q2sfZIpCI1ZiJnmi2-IrZCqwummfJB94uVmqgT-ZWkyeIrICU8GpPvAOdmUfiVtYRmmA7bVAaKPuerJUcRUisveOe5Jp36-3fUK7VlDvwcme0SaJiwJU9B1y1EkF6YTQ00g";
string message = "some test message";
string tickerText = "example test GCM";
string contentTitle = "content title GCM";
string postData =
"{ \"registration_ids\": [ \"" + deviceId + "\" ], " +
"\"data\": {\"tickerText\":\"" + tickerText + "\", " +
"\"contentTitle\":\"" + contentTitle + "\", " +
"\"message\": \"" + message + "\"}}";
首先, - >请问这种方法将有助于我正确地发送推送通知?或者它可以提高到更好?
First Of All --> Does This Method Will Helps me to send a push notification correctly ?? or it can be improved to be better ?
如果是好...
这是我在哪里可以得到浏览器键
??
from where can i get the Browser KEY
??
在此先感谢:)
推荐答案
您必须获得来自谷歌的API控制台您的浏览器的密钥。
You have to obtain your Browser-Key from Google APIs Console. https://code.google.com/apis/console
您Browserkey将是40个字节的大小。
Your Browserkey will be 40 bytes in size.
您可以参考进一步的帮助。
You can refer http://developer.android.com/google/gcm/gs.html for further help.
这篇关于使用Asp.net推送通知(GCM)(未收到通知)(浏览器密钥)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!