[英]Notification logo not shown when app not running (FCM)
So i have implemented FCM for notifications. 所以我已经实现了FCM通知。 So, we can also send some data along with an notification using Firebase Cloud Messaging.
因此,我们还可以使用Firebase云消息传递一些数据和通知。 Here i have created a channel and registed the device to a "general" topic.
在这里,我创建了一个频道,并将设备注册为“常规”主题。
Here is my code : 这是我的代码:
package com.femindharamshi.fcmtrial; 包com.femindharamshi.fcmtrial;
import android.app.NotificationManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.util.Log;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import java.util.Map;
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Map m = remoteMessage.getData();
showNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody(), m);
Class me = remoteMessage.getClass();
Log.d("MessageDateRecieved", ""+me.toString());
}
public void showNotification(String title, String message, Map m) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "MyNotifications")
.setContentTitle(title)
.setSmallIcon(R.drawable.small_logo)
.setAutoCancel(true)
.setContentText(message);
NotificationManagerCompat manager = NotificationManagerCompat.from(this);
manager.notify(999, builder.build());
}
}
Now i am having following 2 issues : 现在我有以下2个问题:
Icon shown for notification when your app is not running can only be monochrome, so icon with transparency should be used as a shape and color for it can be provided separately. 当您的应用未运行时显示的通知图标只能是单色,因此应使用具有透明度的图标作为形状,并且可以单独提供颜色。 It looks like these lines inside
application
tag in AndroidManifest.xml
. 它看起来像
AndroidManifest.xml
application
标记内的这些行。
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/icon_notification_shape" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/color_notification" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.