简体   繁体   English

牛轧糖中的通知图标问题

[英]Notification icon issue in Nougat

I have implemented Firebase push notification in my project.我在我的项目中实现了 Firebase 推送通知。 I have got stuck in one issue, Notification icon not show in Nougat but same code display in other versions.我遇到了一个问题,Nougat 中不显示通知图标,但在其他版本中显示相同的代码。 I have search a lot and try different solutions like white icons, icons placed in mipmap folder dimension wise, same icons in drawable folders,also tried manifest code but not getting success still show gray box in notification panel.我进行了很多搜索并尝试了不同的解决方案,例如白色图标、放置在 mipmap 文件夹尺寸中的图标、可绘制文件夹中的相同图标、也尝试了清单代码但未成功仍然在通知面板中显示灰色框。

here is my Notification code:这是我的通知代码:

 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());


}

Manifest file清单文件

 <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" />

I have solved my problem.我已经解决了我的问题。 Actually there is no issue with above code but issued in app icon, icon is fill with gradient background so that it always show gray in Nougat, to avoid this issue i have just replace plain icon logo without background and convert it to white icon and that it, its working !!实际上上面的代码没有问题,但在应用程序图标中发出,图标填充渐变背景,因此它在牛轧糖中始终显示灰色,为避免此问题,我只需替换没有背景的普通图标徽标并将其转换为白色图标它,它的工作!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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