gpt4 book ai didi

java - Firebase 通知白圈问题

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:27:03 26 4
gpt4 key购买 nike

<分区>

Firebase Notification 有问题,如果我在应用程序在屏幕上运行时发送通知,通知会正确显示,如下所示:

enter image description here

enter image description here

如果我在应用程序在后台运行时发送通知,通知将如下所示:

enter image description here

enter image description here

这是我的 FirebaseMessagingService

    public class AppFirebaseMessagingService extends FirebaseMessagingService {

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
sendNotification(remoteMessage);
}

private void sendNotification(RemoteMessage remoteMessage) {
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
int icon = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? R.drawable.ic_video_label_white_24dp: R.drawable.ic_launcher;
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setWhen(System.currentTimeMillis());
notificationBuilder.setColor(ContextCompat.getColor(this, R.color.colorPrimary));
notificationBuilder.setSmallIcon(icon);
notificationBuilder.setContentTitle(remoteMessage.getNotification().getTitle());
notificationBuilder.setContentText(remoteMessage.getNotification().getBody());
notificationBuilder.setAutoCancel(true);
notificationBuilder.setSound(defaultSoundUri);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
Intent resultIntent = new Intent(this, MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent pendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.setContentIntent(pendingIntent);
notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
}

NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}

为什么会这样?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com