0
我想在android手機上收到gcm通知時刪除聲音通知。我在我的代碼中設置了data.sound=0
,但沒有任何結果。即使應用已關閉,Android也會播放聲音! 有什麼方法可以實現我的目標? 謝謝。c#android GCM通知禁用聲音
public void SendNotification(string deviceId, string message, int badgeCount)
{
string GoogleAppID = "....";
var SENDER_ID = ".....";
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=0&data.message={0} &data.time={1} &data.badge={3} &data.sound={4}®istration_id={2}", message, DateTime.UtcNow, regID, badgeCount, "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();
}
}
如何在C#中編寫Android應用程序? – user4759923
VS .NET Pro 2013,它是一個WFA應用程序 – seq16