Firebase 云消息推送通知不适用于 Android Kitkat
Firebase Cloud Messaging Push Notifications not working on Android Kitkat
我正在尝试使用 FCM [firebase 云消息传递]
向我的应用添加推送通知功能
通知将出现在我的 摩托罗拉 Moto G6 - Android 9 上。但是,通知不会出现在我的 Samsung galaxy grand Max - Android 4.4.4
上
这是我的代码:
主要活动:
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());
}
}
您好,问题已解决,实际上它正在运行,但 phone 将其作为 垃圾 通知删除。
我正在尝试使用 FCM [firebase 云消息传递]
向我的应用添加推送通知功能通知将出现在我的 摩托罗拉 Moto G6 - Android 9 上。但是,通知不会出现在我的 Samsung galaxy grand Max - Android 4.4.4
上这是我的代码:
主要活动:
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());
}
}
您好,问题已解决,实际上它正在运行,但 phone 将其作为 垃圾 通知删除。