我正在使用 Firebase 向用户发送通知。我可以很好地发送基本通知。但是,我无法将该通知转换为提醒通知。我尝试了 StackOverflow 的多种解决方案,但没有一个与我合作。
以下是我用于接收推送通知的相应课程。
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage message) {
super.onMessageReceived(message);
NotificationManager mNotificationManager = getSystemService(NotificationManager.class);
NotificationChannel channel = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
channel = new NotificationChannel("channel",
"Channel description",
NotificationManager.IMPORTANCE_HIGH);
mNotificationManager.createNotificationChannel(channel);
}
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(getApplicationContext(), "channel")
.setSmallIcon(R.drawable.googleg_standard_color_18)
.setContentTitle(message.getNotification().getTitle())
.setContentText(message.getNotification().getBody())
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(Notification.PRIORITY_HIGH);
mNotificationManager.notify(0, mBuilder.build());
}
}