应用程序被杀死时,Oreo FCM通知图标不显示(完全关闭)

时间:2018-09-18 14:07:14

标签: android push-notification firebase-cloud-messaging android-notifications android-8.0-oreo

当应用程序完全关闭(被杀死)时,Android Oreo无法在状态栏中和通知本身上正确显示通知图标。当在前台打开应用程序时,它运行良好。

    int notificationId = new Random().nextInt(60000);

    PendingIntent contentIntent = PendingIntent.getActivity(ctx, notificationId + 1,
            intent, PendingIntent.FLAG_ONE_SHOT);

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

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        setupChannels();
    }
    String CHANNEL_ID = getString(R.string.default_notification_channel_id);

    Bitmap bitmap = null;
    if (imageUrl != null && !imageUrl.equalsIgnoreCase("")) {
        bitmap = getBitmapfromUrl(imageUrl);
    }
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(ctx, CHANNEL_ID)
                    .setContentTitle(notificationTitle)
                    .setStyle(new NotificationCompat.BigPictureStyle()
                            .setSummaryText(notificationMsg)
                            .bigPicture(bitmap))/*Notification with Image*/
                    .setSound(defaultSoundUri)
                    .setContentText(msg)
                    .setChannelId(CHANNEL_ID)
                    .setAutoCancel(true)
                    .setContentIntent(contentIntent)
                    .setPriority(Notification.PRIORITY_HIGH);

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mBuilder.setColor(getResources().getColor(R.color.colorPrimaryDark));
    }

    mBuilder.setLargeIcon(BitmapFactory.decodeResource(ctx.getResources(), getNotificationIcon()));
    mBuilder.setSmallIcon(getNotificationIcon());

    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    mBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;

    private int getNotificationIcon() {
       boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O);
       return useWhiteIcon ? R.mipmap.ic_launcher_icon_round : R.mipmap.ic_launcher;
    }

预先感谢...

0 个答案:

没有答案