这是替代解决方法。
我们可以从中获取drawable sbn.getNotification().extras.getInt("android.icon")
,然后使用customview在通知中显示这个drawable。
这是使用 android.icon 值获取 Drawable 的方法:
RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.custom_push_notification);
contentView.setImageViewResource(R.id.image, R.mipmap.ic_launcher);
contentView.setTextViewText(R.id.title, notificationModel.getTitle());
contentView.setTextViewText(R.id.text, notificationModel.getBody());
try {
//now get the context of other app and then get drawable from resoures
Drawable drawable1 = context.createPackageContext(notificationModel.getPackageName(), CONTEXT_IGNORE_SECURITY).getDrawable(notificationModel.getIcon());
Bitmap bitmap = drawableToBitmap(drawable1);
contentView.setImageViewBitmap(R.id.image, bitmap);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
我notificationModel
的是:
notificationModel.setKey(sbn.getId());