Я пытаюсь реализовать класс, который получает уведомление от 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());