У меня странное поведение в FCM (облачные сообщения Firestore).
Странное поведение, о котором я говорю, заключается в следующем: когда я отправляю уведомление на телефон, и приложение в данный момент открыто, я получаю хорошее сообщение с правильным стилем (у него есть изображение обложки)
Когда я отправляю это же уведомление, и мое приложение находится в фоновом режиме, я не получаю правильную стилизацию (изображение обложки отсутствует)
Что здесь может быть не так? (Разработка Android действительно доставляет мне трудности)
Вот мой код для обработки предстоящих уведомлений в FCM
public class MyFirebaseInstanceService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
showNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody(), remoteMessage.getData());
}
private void showNotification(String title, String body, Map<String, String> data) {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String NOTIFICATION_CHANNEL_ID = "com.my.app.alarm";
// Build cover url
String coverURL = "";
if (data.containsKey("cover")) {
coverURL = "https://localhost" + data.get("cover") + ".jpg";
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "Notification", NotificationManager.IMPORTANCE_DEFAULT);
notificationChannel.setDescription("Reminder Channel");
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.BLUE);
notificationManager.createNotificationChannel(notificationChannel);
}
// TO open New added Games fragment
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra("FragmentFromNotification", "NewAddedReleases");
PendingIntent notificationIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);
notificationBuilder.setAutoCancel(true)
.setSmallIcon(R.mipmap.ic_launcher)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setContentTitle(title)
.setContentText(body)
.setContentIntent(notificationIntent)
.setContentInfo("Info");
// Load new game cover here
if (!coverURL.isEmpty()) {
Bitmap bmp = null;
try {
bmp = Picasso.with(getApplicationContext()).load(coverURL).get();
NotificationCompat.BigPictureStyle bps = new NotificationCompat.BigPictureStyle().bigPicture(bmp);
notificationBuilder.setStyle(bps);
} catch (IOException e) {
e.printStackTrace();
}
}
notificationManager.notify(new Random().nextInt(), notificationBuilder.build());
}
@Override
public void onNewToken(String s) {
super.onNewToken(s);
}
}