Android:BigPictureStyle的通知在android nougat中不起作用

时间:2017-12-23 21:52:06

标签: android firebase android-notifications android-notification-bar

问题1:无法为推送通知更改徽标的颜色或徽标背景。

问题2:无法使用BigPictureStyle在通知中显示位图图像。

所有这个问题都出现在Android Nougat中。我尝试搜索解决方案,但似乎没有从stackoverflow或其他博客获得任何解决方案。尝试使用setColor(),但它也没有工作。 图标为白色,背景也是透明的。

BigPictureStyle适用于API级别19的模拟器。

    private void sendNotification(String title,String messageBody) {
        NotificationManager notificationManager = (NotificationManager)
                getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);

        Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);

        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP);

        PendingIntent intent =
                PendingIntent.getActivity(getApplicationContext(), 0,
                        notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);

        Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
                R.mipmap.logo);
        int icon = R.mipmap.icon;
        long when = System.currentTimeMillis();

       Notification notification = new NotificationCompat.Builder(getApplicationContext(),"default")
                .setContentTitle(title)
                .setContentText(messageBody)
                .setContentIntent(intent)
                .setSmallIcon(icon)
                .setWhen(when)
                .setStyle(new NotificationCompat.BigPictureStyle()
                        .bigPicture(bitmap).setSummaryText(messageBody))
               .setColor(getResources().getColor(R.color.colorPrimary))
                .build();

        notification.flags |= Notification.FLAG_AUTO_CANCEL;

// Play default notification sound
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notificationManager.notify(0, notification);
    }

0 个答案:

没有答案