推送通知图标是棒棒糖上方的白色

时间:2017-01-12 18:00:32

标签: android push-notification android-notifications

我知道在Lollipop中,通知图标会有一些设计级别的更改,这就是为什么通知图标在棒棒糖发布之上是白色的。

但是我需要显示通知的确切应用图标,是否有可能?

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

3 个答案:

答案 0 :(得分:3)

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

  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);
         }

答案 1 :(得分:0)

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

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());
    }

答案 2 :(得分:0)

您可以通过添加参数"图像"来显示通知中的任何图像。发送参数时。

将FCM与图像一起使用是资产文件夹:

{"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图片。