【问题标题】:Push notification icon is white above Lollipop [duplicate]Lollipop上方的推送通知图标为白色[重复]
【发布时间】:2017-01-12 18:00:32
【问题描述】:

我知道 Lollipop 对通知图标的设计级别进行了一些更改,这就是为什么通知图标在 lollipop 版本上方是白色的原因。

但我需要显示通知的确切应用程序图标,这可能吗?

在棒棒糖及以上平台上,有些应用在通知中显示相同的应用图标。

【问题讨论】:

标签: android push-notification android-notifications


【解决方案1】:

您可以使用此方法在棒棒糖上方设置白色图标。

  if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) 
  {
        Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher);
        mBuliderREC.setLargeIcon(icon);
        mBuliderREC.setSmallIcon(R.drawable.notification_icon);
  } else {
               mBuliderREC.setSmallIcon(R.drawable.ic_launcher);
         }

【讨论】:

  • 我可以知道在上述棒棒糖操作系统的情况下 setlargeIcon 和 setSmallicon 代表什么。
  • 在 setlargeIcon 中你可以设置普通的应用程序图标,在 setsmall 图标中你必须为具有白色背景的图标制作新图像,这样你就可以看到通知 cme 的时间,否则你可以得到白色图像
  • 如果您有想法,请接受答案。谢谢。
  • 感谢 Sachin,它确实有效...非常感谢
  • 欢迎亲爱的..请接受答案。
【解决方案2】:

同样的问题,我在我的一个项目中遇到过,但我用下面的代码解决了。 请检查它可能对你有帮助

private void sendNotification(String message) {
        int NOTIFICATION_ID = (int) Calendar.getInstance().getTimeInMillis();
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.loading_icon)
                .setContentTitle(getString(R.string.app_name))
                .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND)
                .setContentText(message);
        mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
        Intent resultIntent = new Intent(this, HomeActivity.class);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);
        mBuilder.setAutoCancel(true);
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    }

【讨论】:

  • 请说明答案如何有助于使通知图标显示为白色。
  • 实际上,我使用颜色代码(与应用程序颜色相关)填充圆圈并将应用程序图标置于中心(这将自动居中)。试试上面的代码就行了。
【解决方案3】:

您可以在发送参数时添加参数“image”在通知中显示任何图像。

使用带有图片的 FCM 是 assets 文件夹:

{"to":"[add your token]","notification":{"title":"[add title]","body":"[add your message]","image":"www/images/test_image.png"},"priority":"high"}

将 FCM 与可绘制文件夹中的图像一起使用:

{"to":"[add your token]","notification":{"title":"[add title]","body":"[add your message]","image":"ic_icon"},"priority":"high"}

将 FCM 与来自外部链接的图像一起使用:

{"to":"[add your token]","notification":{"title":"[add title]","body":"[add your message]","image":"http://www.test.com/test_img.png"},"priority":"high"}

将 GCM 与资产文件夹中的图像一起使用:

{"registration_ids": ["[please dont change]" ],"data": {"tickerText":"example test GCM","contentTitle":"content title GCM","message": "Enter your message","title":"GILAC","image":"www/images/test_img.png"}}

将 GCM 与可绘制文件夹中的图像一起使用:

{"registration_ids": ["[please dont change]" ],"data": {"tickerText":"example test GCM","contentTitle":"content title GCM","message": "Enter your message","title":"GILAC","image":"ic_icon"}}

将 GCM 与来自外部链接的图像一起使用:

{"registration_ids": ["[please dont change]" ],"data": {"tickerText":"example test GCM","contentTitle":"content title GCM","message": "Enter your message","title":"GILAC","image":"http://www.test.com/test_img.png"}}

注意:通知图标/图像必须是 png 图像。

【讨论】:

  • 实际问题是,当应用程序处于后台时,我无法处理 FCM 推送通知的 onMessageReceived() 方法。所以没有调用该方法似乎不可能按照您的建议设置通知图标。
猜你喜欢
  • 2018-10-24
  • 1970-01-01
  • 2018-05-26
  • 2015-04-07
  • 2015-06-26
  • 2016-05-01
  • 1970-01-01
  • 2015-08-28
相关资源
最近更新 更多