【问题标题】:Notification icon issue in Nougat牛轧糖中的通知图标问题
【发布时间】:2020-10-12 02:49:22
【问题描述】:

我在我的项目中实现了 Firebase 推送通知。我遇到了一个问题,Nougat 中不显示通知图标,但在其他版本中显示相同的代码。 我进行了很多搜索并尝试了不同的解决方案,例如白色图标,放置在 mipmap 文件夹尺寸中的图标,可绘制文件夹中的相同图标,还尝试了清单代码但未成功仍然在通知面板中显示灰色框。

这是我的通知代码:

 private void sendNotification(String title, String msg) {

    Uri defaultSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    Intent intent = new Intent(getApplicationContext(), MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    String NOTIFICATION_CHANNEL_ID = "101";

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        @SuppressLint("WrongConstant")
        NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "Notification", NotificationManager.IMPORTANCE_MAX);

        //Configure Notification Channel
        notificationChannel.setDescription(msg);
        notificationChannel.enableLights(true);
        notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
        notificationChannel.enableVibration(true);

        notificationManager.createNotificationChannel(notificationChannel);
    }

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
            .setSmallIcon(R.drawable.ic_notification_app)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
            .setContentTitle(title)
            .setAutoCancel(true)
            .setSound(defaultSound)
            .setContentText(msg)
            .setContentIntent(pendingIntent)
            //.setStyle(style)
            // .setLargeIcon(bitmap)
            .setWhen(System.currentTimeMillis())
            .setPriority(Notification.PRIORITY_MAX);

    int id = (int) System.currentTimeMillis();
    notificationManager.notify(id, notificationBuilder.build());


}

清单文件

 <meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/ic_notification_app" />
   
    <meta-data
        android:name="com.google.firebase.messaging.default_notification_color"
        android:resource="@color/colorAccent" />

【问题讨论】:

    标签: push-notification notifications android-7.0-nougat android-7.1-nougat


    【解决方案1】:

    我已经解决了我的问题。实际上上面的代码没有问题,但在应用程序图标中发出,图标填充渐变背景,因此它在牛轧糖中始终显示灰色,为避免此问题,我只需替换没有背景的普通图标徽标并将其转换为白色图标它,它的工作!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-20
      • 2016-12-30
      • 2020-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多