android应用程序正确接收了通知,但显示了白色方形框作为通知图标。 我想设置适当的通知图标。 这是我的C#代码,我想从网页按钮单击发送通知到android应用程序。
public string SendPushNotification(string deviceId)
{
string response;
try
{
string serverKey = "AAAAu0:******cw"; // Something very long
string senderId = "1:******";
// Also something very long,
// got from android
// string deviceId = "//topics/all"; // Use this to notify all devices,
// but App must be subscribed to
// topic notification
WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
tRequest.Method = "post";
tRequest.ContentType = "application/json";
var data = new
{
to = deviceId,
notification = new
{
body = "Greetings",
title = "Augsburg",
sound = "Enabled"
}
};
var serializer = new JavaScriptSerializer();
var json = serializer.Serialize(data);
Byte[] byteArray = Encoding.UTF8.GetBytes(json);
tRequest.Headers.Add(string.Format("Authorization: key={0}", serverKey));
tRequest.Headers.Add(string.Format("Sender: id={0}", senderId));
tRequest.ContentLength = byteArray.Length;
using (Stream dataStream = tRequest.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
using (WebResponse tResponse = tRequest.GetResponse())
{
using (Stream dataStreamResponse = tResponse.GetResponseStream())
{
using (StreamReader tReader = new StreamReader(dataStreamResponse))
{
String sResponseFromServer = tReader.ReadToEnd();
response = sResponseFromServer;
}
}
}
}
}
catch (Exception ex)
{
response = ex.Message;
}
return response;
}
public string all()
{
con.Open();
string query = "SELECT distinct token FROM tbl_user";
MySqlCommand cmd = new MySqlCommand(query, con);
cmd.CommandType = CommandType.Text;
dr = cmd.ExecuteReader();
string token = "";
while (dr.Read())
{
string response = SendPushNotification(dr["token"].ToString());
}
con.Close();
return token;
}
答案 0 :(得分:1)
将此行放入清单文件中-
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@mipmap/notification_icon" />