简体   繁体   中英

android notification bar (icon) show not correctly

Im currently working on my android music application project. And I'm facing the notification problem.

pic source: http://postimg.org/image/enticjvjl/

please open the link first, When the song is pressed, the song plays correctly,everything is ok. However, in the first pic,the icon in the left hand side is not scaled correctly, which cause the problem. And within 1 sec, the notification icon is shown correctly as we can see in the second pic (the first icon with yellow background is my application).

Here is the code I'm using to create the notification bar.

    Bitmap largeIcon;
    largeIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.launcher);
    int height = (int) this.getResources().getDimension(android.R.dimen.notification_large_icon_height);
    int width = (int) this.getResources().getDimension(android.R.dimen.notification_large_icon_width);
    largeIcon = Bitmap.createScaledBitmap(largeIcon, height, width, false);

    builder.setContentIntent(pendInt)
      .setSmallIcon(R.drawable.launcher)
      .setLargeIcon(largeIcon)
      .setTicker(songTitle)
      .setOngoing(true)
      .setWhen(System.currentTimeMillis())
      .setContentTitle("Playing")
      .setContentText(songTitle);
    Notification not = builder.build();

    startForeground(NOTIFY_ID, not);

I believe your problem is that you don't scale an icon which you set in setSmallIcon method. Try setting same icon as in setLargeIcon method. Or the other way around :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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