简体   繁体   中英

Android 12 does not showing notification icon

Notification icon is not displaying the app icon, this issue is only in android 12.

My code:- Notification method:-


Intent intent = new Intent(this, FragmentController.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
         PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                /*PendingIntent.FLAG_ONE_SHOT*/ PendingIntent.FLAG_IMMUTABLE);

        String channelId = "Notification channel ID";
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(this, channelId)
                        .setSmallIcon(R.drawable.logo_round)
                        //.setSmallIcon(R.mipmap.ic_launcher_new_logo_round) //<- this not working
                        .setLargeIcon(BitmapFactory.decodeResource(PushNotificationService.this.getResources(),R.drawable.logo_round))
                        .setContentTitle(Title)
                        .setContentText(messageBody)
                        .setAutoCancel(true)
                        .setSound(defaultSoundUri)
                        .setContentIntent(pendingIntent);

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        // Since android Oreo notification channel is needed.
        NotificationChannel channel = new NotificationChannel(channelId,
                "Channel human readable title",
                NotificationManager.IMPORTANCE_DEFAULT);
        notificationManager.createNotificationChannel(channel);

        notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

Android manifest file:- (Under application tag)


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

These answers are not helping: Android Push Notifications: Icon not displaying in notification, white square shown instead

and

How to set the app icon as the notification icon in the notification drawer

在此处输入图像描述

What you're seeing here is your app icon (which is round I guess), without all the fancy colors, and displayed on a blue round.

Here is what it looks like with a transparent icon, which has a mushroom's shape (I guess it'll help you understand what I mean)
在此处输入图像描述

Your notification icon must be a simple shape, with a single color, and a transparent background (like the one you can see on your screenshot)
在此处输入图像描述

I'll update my answer with the official documentation and keynote as soon as I find it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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