【问题标题】:Firebase Notification not showing iconFirebase 通知未显示图标
【发布时间】:2017-08-07 12:21:53
【问题描述】:

我想在应用程序处于前台和后台时都使用 firebase 发送通知。我能够做到这一点,但问题是我希望显示我的启动器图标而不是默认的 firebase 通知图标(一些白色方形圆圈)。我已经实现了以下代码,但仍然没有显示。我不知道这里有什么问题。这是代码 FirebaseMessagingService

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.setFlags(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("Dream 11 Prediction Guru");
        notificationBuilder.setContentText(remoteMessage.getNotification().getBody());
        notificationBuilder.setAutoCancel(true);
        notificationBuilder.setSmallIcon(R.mipmap.ic_launcher_round);
        //notificationBuilder.setLargeIcon(R.mipmap.ic_launcher);
        notificationBuilder.setContentIntent(pendingIntent);

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

}

FirebaseInstanceIdService 代码

public class MyFirebaseInstanceIdService extends FirebaseInstanceIdService {

    private static final String REG_TOKEN = "REG_TOKEN";

    @Override
    public void onTokenRefresh() {
        String recent_token = FirebaseInstanceId.getInstance().getToken();
        Log.d(REG_TOKEN,recent_token);
    }

}

【问题讨论】:

  • 您是使用 Firebase 控制台发送推送通知还是实现了服务器端?
  • 使用firebase控制台发送消息
  • 检查这个我已经回答的解决方案:stackoverflow.com/a/45280972/5928383

标签: android firebase firebase-notifications


【解决方案1】:

尝试在清单文件中添加:

<meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@mipmap/ic_launcher" />

【讨论】:

  • 你能在你的问题中添加你的问题的图像吗,我需要看看真正发生了什么谢谢。 @NikeshPatel
  • 是的,等一下
  • 我已经添加了我得到的图像
  • 我明白了,您使用的是什么版本的 firebase? @NikeshPatel
  • 它的 firebase 消息传递:10.2.0
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-02-11
  • 1970-01-01
  • 2019-08-05
  • 1970-01-01
  • 2020-02-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多