gpt4 book ai didi

android - 如果应用程序在后台,Firebase 通知将无法正常工作

转载 作者:行者123 更新时间:2023-11-29 01:15:57 25 4
gpt4 key购买 nike

<分区>

我有一个用于 Firebase 的 FirebaseMessagingService 类:

public class FcmMessagingService extends FirebaseMessagingService {

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
String message = remoteMessage.getNotification().getBody();

Map<String, String> params = remoteMessage.getData();

Bitmap remote_picture = null;
remote_picture = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.logo);

intent = new Intent(this, HomeDrawer.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setContentTitle("Notification Title");
notificationBuilder.setContentText(message);
notificationBuilder.setSmallIcon(R.drawable.ic_notif);
notificationBuilder.setLargeIcon(remote_picture);
notificationBuilder.setAutoCancel(true);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification noti = new Notification();
noti = notificationBuilder.build();
//notificationBuilder.setVibrate(new long[] { 1000, 1000});
//notificationBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
noti.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
notificationManager.notify(0,noti);

super.onMessageReceived(remoteMessage);
}

如果应用程序在后台,(没有主动打开,但在后台,没有关闭)通知smallIcon和LargeIcon不会出现,而是出现android默认的,如果我改变了

 intent = new Intent(this, HomeDrawer.class);

对于任何其他 Activity 类,它不会打开我指定的类,而是打开我在后台打开的最后一个类。

我做错了什么?如果后台 SmallIcon 和 LargeIcon 不能正常工作。但是,通知消息看起来很好,而且 remoteMessage.getData();正确获取数据,这都是关于图标和 Intent 类的行为。

提前致谢。

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