简体   繁体   English

通知图标问题

[英]Notification Icon Issue

Notification Icon is not appearing in redmi MI device,it appears the default ic_launcher while in every other devices image is appears.API 22 and Android 5.1.1 and minsdk=15,target=24.I had tested in many other mobiles there is no issue but in my device this issue is there.Can you please get rid out from this problem. 通知图标没有出现在redmi MI设备中,它出现了默认的ic_launcher,而在其他每个设备中都出现了图像.API 22和Android 5.1.1以及minsdk = 15,target = 24.我曾在许多其他手机中测试过没有问题,但在我的设备中,这个问题就在那里。你可以摆脱这个问题。 my code is 我的代码是

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

Thank you in advance 先感谢您

please use two icon in your notification. 请在通知中使用两个图标。 first one is small white png so that it will show in status bar and second one is app logo. 第一个是小白色png,它将显示在状态栏中,第二个是app徽标。

Update white icon in below folder with difference size. 更新下面的文件夹中的白色图标与不同大小。

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

Suppose this image name is app_logo_white_small.png. 假设此图像名称为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());

I hope, it will help you. 我希望,它会对你有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM