抱歉回复晚了,实际上我也遇到了同样的问题并找到了解决方法,因此我认为它可以帮助其他用户。
由于我们不能同时使用BigTextStyle
和BigPictureStyle
方法来构建NotificationCompat.Builder
,因此我们需要创建自定义视图CustomView
.
我们可以使用NotificationCompat.Builder
的setCustomBigContentView(RemoteViews)
方法,创建我们自己的视图以显示大图和大文本。
请查看以下代码:
PendingIntent pendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), i,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setContentTitle("YOUR_APP_NAME");
notificationBuilder.setContentText(body);
notificationBuilder.setTicker("YOUR_APP_NAME");
notificationBuilder.setAutoCancel(true);
notificationBuilder.setSound(defaultSoundUri);
notificationBuilder.setCustomBigContentView(remoteView("YOUR_MESSAGE_TO_SHOW"));
notificationBuilder.setSmallIcon(getNotificationIcon(notificationBuilder));
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify((int) System.currentTimeMillis(), notificationBuilder.build());
以下是我们从
setCustomBigContentView()
方法中调用的RemoteViews。
private RemoteViews remoteView(String message)
{
RemoteViews views;
views = new RemoteViews(getPackageName(), R.layout.YOUR_LAYOUT_HERE);
views.setImageViewBitmap(R.id.YOUR_BIG_IMAGE_ID_FROM_LAYOUT, bitmap);
views.setImageViewBitmap(R.id.YOUR_APP_ID_FROM_LAYOUT, BitmapFactory.decodeResource(getResources(), R.drawable.APP_ICON_OF_YOUR_APP));
views.setTextViewText(R.id.YOUR_BIG_TEXTVIEW_ID_FROM_LAYOUT, message);
return views;
}
我已经创建了类似于
的自定义通知。