gpt4 book ai didi

Android 推送通知状态图标问题

转载 作者:太空狗 更新时间:2023-10-29 14:41:00 24 4
gpt4 key购买 nike

我在使用推送通知 Firebase 时遇到问题,问题 :应用程序图标在棉花糖及上方显示为白色,因此我创建了一组白色和透明的图标,现在推送通知图标以根据需要显示仅当应用程序位于前景 当用户收到通知并且应用关闭时,图标本身显示为白色。

我的 list

<application
android:name="com.xxxx"
android:allowTaskReparenting="true"
android:hardwareAccelerated="true"
android:icon="@drawable/ic_xxxx"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/AppTheme">

通知代码:当我收到推送通知时

Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.xxxxxx)
.setColor(getResources().getColor(R.color.accent))
.setContentTitle(messageTitle)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(contentIntent);
} else {
notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(messageTitle)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(contentIntent);
}



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

关于消息接收码

 @Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//Displaying data in log
//It is optional
Log.d(TAG, "Notification Message TITLE: " + remoteMessage.getNotification().getTitle());
Log.d(TAG, "Notification Message BODY: " + remoteMessage.getNotification().getBody());
Log.d(TAG, "Notification Message DATA: " + remoteMessage.getData().toString());

//Calling method to generate notification
//remoteMessage.getNotification().getBody()
sendNotification(remoteMessage.getNotification().getTitle(),
remoteMessage.getNotification().getBody(), remoteMessage.getData());
}

最佳答案

那里有两种类型的通知。

1.) 使用默认参数

    String title = remoteMessage.getNotification().getTitle();
String body = remoteMessage.getNotification().getBody();

服务器端代码:

{ "data": {
"score": "5x1",
"time": "15:10"
},
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}

这种类型的实现仅在应用程序打开或处于后台时有效。您将收到通知消息(如您​​所说,将出现空白通知)但您不会从中获取任何数据。

2.) 使用 map

   Map data =  remoteMessage.getData();

服务器端代码:

{
"message":{
"token" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification" : {
"body" : "This is an FCM notification message!",
"title" : "FCM Message",
}
}
}

即使在应用程序关闭后也会收到。它不会产生空白的白色通知。

关于Android 推送通知状态图标问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48149984/

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