我在使用推送通知Firebase时遇到问题, 问题 : 应用程序图标在棉花糖及以上显示为白色,因此我创建了白色和透明的图标集,现在推送通知图标显示为我需要但仅当应用程序位于前景<时/ strong>当用户收到通知且应用已关闭时,图标会显示为白色。
我的清单
<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());
}
答案 0 :(得分:0)
那里有两种类型的通知。
1。)使用默认参数
String title = remoteMessage.getNotification().getTitle();
String body = remoteMessage.getNotification().getBody();
服务器端代码:
{ "data": {
"score": "5x1",
"time": "15:10"
},
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}
此类实施仅在应用程序处于打开状态或后台时才有效。您将收到通知消息(如您所说,将显示空白通知),但您无法从中获取任何数据。
2。)使用地图
Map data = remoteMessage.getData();
服务器端代码:
{
"message":{
"token" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification" : {
"body" : "This is an FCM notification message!",
"title" : "FCM Message",
}
}
}
即使在应用关闭后,这也会收到。它不会产生空白白色通知。
答案 1 :(得分:0)
如果通知图标的问题为白色。尝试在清单
中添加此代码<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/app_icon" />