Я пытаюсь добавить функцию push-уведомлений в свое приложение, используя FCM [облачные сообщения firebase]
Уведомление появится на моем Motorola Moto G6 - Android 9 . Однако уведомления не будут появляться на моем Samsung galaxy grand Max - Android 4.4.4
Вот мой код:
MainActivity:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("MyNotifications", "MyNotifications", NotificationManager.IMPORTANCE_DEFAULT);
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(channel);
}
MyMessagingService.class:
package com......
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.innocentapps.musicplayer2.R;
public class MyMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
showNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());
}
public void showNotification(String title, String message) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "MyNotifications")
.setContentTitle(title)
.setSmallIcon(R.drawable.ic_tap_and_play)
.setAutoCancel(true)
.setContentText(message);
NotificationManagerCompat managerCompat = NotificationManagerCompat.from(this);
managerCompat.notify(999, builder.build());
}
}