Android Firebase通知与图像不工作



我正在尝试实现一个类,该类接收firebase通知,如果存在"image"键,也会显示它。它按预期接收通知,但没有图像。我试着在控制台中输出键"图像"是否存在,但什么都没有输出。如果有人能帮忙,我会很高兴的。

代码的相关部分如下:

[Service]
[IntentFilter(new[] {
"com.google.firebase.MESSAGING_EVENT"
})]
class MyFirebaseMessagingService : FirebaseMessagingService
{
public override void OnMessageReceived(RemoteMessage message)
{
base.OnMessageReceived(message);
SendNotifications(message.GetNotification().Body, message.GetNotification().Title,message.Data);
}
public void SendNotifications(string body, string Header, IDictionary<string, string> data)
{
Notification.Builder builder = new Notification.Builder(this);
builder.SetSmallIcon(Resource.Drawable.favicon96_96);
var intent = new Intent(this, typeof(MainActivity));
intent.AddFlags(ActivityFlags.ClearTop);
PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0, intent, 0);
builder.SetContentIntent(pendingIntent);
builder.SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.favicon96_96));
builder.SetContentTitle(Header);
builder.SetContentText(body);
builder.SetDefaults(NotificationDefaults.Sound);
builder.SetAutoCancel(true);
if (data.ContainsKey("image"))
{
Console.WriteLine("There is an image => "+data["image"]);
var urlString = data["image"].ToString();
var url = new URL(urlString);
var connection = (HttpURLConnection)url.OpenConnection();
connection.DoInput = true;
connection.Connect();
var input = connection.InputStream;
var bitmap = BitmapFactory.DecodeStream(input);
Notification.BigPictureStyle picStyle = new Notification.BigPictureStyle();
picStyle.BigPicture(bitmap);
picStyle.SetSummaryText(body);
connection.Dispose();
builder.SetStyle(picStyle);
}
else
{
Console.WriteLine("====== THERE ISNT ANY IMAGE ");
}

NotificationManager notificationManager = (NotificationManager)GetSystemService(NotificationService);
notificationManager.Notify(1, builder.Build());

您是否发送以下数据中的图像链接?

{
"data": {
"Image": "https://...."
},
"registration_ids": [
"testtoken"
],
"priority": "high"
}

相关内容

  • 没有找到相关文章