简体   繁体   English

应用未运行时未显示通知徽标(FCM)

[英]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个问题:

  1. When the app is not running/killed, then the notification logo (R.drawable.small_logo) residing in my res/drawable folder is not shown instead a gray circle is shown. 当应用程序未运行/终止时,则不会显示驻留在我的res / drawable文件夹中的通知徽标(R.drawable.small_logo),而是显示灰色圆圈。 How do i solve this problem. 我该如何解决这个问题。
  2. If i pass data through this message i can capture it in a Map. 如果我通过此消息传递数据,我可以在地图中捕获它。 Now imaging the app is not running and i want to save this data in SharedPreferences, then how is it possible ? 现在成像应用程序没有运行,我想在SharedPreferences中保存这些数据,那怎么可能?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM