确保你的应用已经获得了适当的通知的权限。
检查你的应用是否正确地实现了FCM的消息接收器,包括在AndroidManifest.xml中设置正确的 intent-filter,如下所示:
{
"to" : "device_token",
"notification" : {
"title" : "FCM Notification",
"body" : "This is a FCM Notification",
"icon" : "icon_name"
}
}
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
}
}
}
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(remoteMessage.getNotification().getBody())
.setSmallIcon(R.drawable.ic_notification)
.setColor(ContextCompat.getColor(this, R.color.colorPrimary