簡體   English   中英

牛軋糖中的通知圖標問題

[英]Notification icon issue in Nougat

我在我的項目中實現了 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" />

我已經解決了我的問題。 實際上上面的代碼沒有問題,但在應用程序圖標中發出,圖標填充漸變背景,因此它在牛軋糖中始終顯示灰色,為避免此問題,我只需替換沒有背景的普通圖標徽標並將其轉換為白色圖標它,它的工作!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM