Android notification displays wrong icon

懵懂的女人 提交于 2019-12-11 06:09:56

问题


I have a static Array with Icon ids:

public static final int[][] ICON_IDS = { {R.drawable.ic_access_alarm_black_24dp, R.drawable.ic_access_time_black_24dp, R.drawable.ic_account_box_black_24dp, R.drawable.ic_add_black_24dp, R.drawable.ic_android_black_24dp, R.drawable.ic_clear_black_24dp, R.drawable.ic_delete_black_24dp },
        { R.drawable.ic_settings_black_24dp, R.drawable.ic_airplanemode_active_black_24dp, R.drawable.ic_filter_list_black_24dp, R.drawable.ic_account_box_black_24dp, R.drawable.ic_airline_seat_individual_suite_black_24dp, R.drawable.ic_delete_black_open_24dp, R.drawable.ic_delete_black_open_24dp}};

I display all the icons and the user can choose one. The id of the chosen icon is passed to the notification manager. It displays the notification like this:

NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(notification.getIconId())
                    .setContentTitle(notification.getTitle());

I have checked with an "test-ImageView" that the id is correct. The ImageView displays the icon the user selected (with setImageResource(notification.getIconId());). But on the notification in the notification bar another icon is displayed or none. If I use .setLargeIcon() it shows the correct icon again.

.setLargeIcon(BitmapFactory.decodeResource(getResources(), notification.getIconId()))

But only in the big icon. The small icon is empty.

The icons are the material icons imported via vector assets.

What is wrong with this?


回答1:


Found out why. You can't use xml resources as Notification Icons.



来源:https://stackoverflow.com/questions/40317819/android-notification-displays-wrong-icon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!