【问题标题】:Notification Icon Issue通知图标问题
【发布时间】:2016-08-22 07:25:35
【问题描述】:

redmi MI 设备中没有出现通知图标,它出现在默认的 ic_launcher 中,而在所有其他设备中出现图像。API 22 和 Android 5.1.1 和 minsdk=15,target=24。我在许多其他手机上测试过没有问题,但在我的设备中,这个问题就在那里。你能摆脱这个问题吗?我的代码是

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setSmallIcon(R.drawable.home1);  //icon appears in device notification bar and right hand corner of notification
    builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.home1));        
    builder.setContentIntent(pendingIntent);      
            builder.setContentTitle(Title);        
    builder.setContentText(message);        
    builder.setSubText(subtext);
    NotificationManager notificationManager = (NotificationManager) getSystemService(context.NOTIFICATION_SERVICE);        
    notificationManager.notify(NOTIFICATION_ID, builder.build()); 

提前谢谢你

【问题讨论】:

  • 你有不同版本的可绘制 home1 用于 hdpi、xhdpi 等吗?
  • 是的,我有,但仍然没有图像图标不来......
  • 请检查drawable home1的所有版本是否相似。
  • 是的,我再次检查并没有所有 .png 图像都有不同的尺寸,比如 hdpi 有 20*20 而其他有其他...

标签: android performance push-notification notifications android-notifications


【解决方案1】:

请在您的通知中使用两个图标。第一个是白色的小png,以便显示在状态栏中,第二个是应用程序徽标。

更新以下文件夹中不同大小的白色图标。

  1. hdpi (36x36)
  2. mdpi (24x24)
  3. xhdpi (48x48)

假设此图像名称为 app_logo_white_small.png。

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setLargeIcon(
                    BitmapFactory.decodeResource(
                            getResources(), R.drawable.app_icon))
            .setSmallIcon(R.drawable.app_logo_white_small)
            .setContentTitle(mContext.getString(R.string.app_name))
            .setDefaults(Notification.DEFAULT_ALL)
            .setContentText(msg)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
            .setContentIntent(getPendingIntent())
            .setAutoCancel(true);
    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

 notificationManager.notify((int) System.currentTimeMillis(), notificationBuilder.build());

希望对你有帮助。

【讨论】:

  • 静止图像在我的设备中不起作用,但它完美地适合味精和所有
  • 能否请您也分享您的图标或通知屏幕截图
  • 150 %sure 因为它在 genymotion 和其他设备中也显示正确,除了 redmi note 3
  • 当然,但是我怎么没有声望分享截图?
  • 默认 ic_launcher 即将进入我的设备
猜你喜欢
  • 2016-10-03
  • 2018-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-12
  • 2018-06-17
  • 2021-11-10
  • 1970-01-01
相关资源
最近更新 更多