问题
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