【发布时间】:2019-09-12 11:37:33
【问题描述】:
我正在使用 Firebase 通知。当应用程序处于前台时 onMessageReceived 被调用并且通知在图像中可见(BigPictureStyle 通知)。但是当应用程序处于终止状态时,不会调用 onMessageReceived,而是调用带有标题和描述的基本通知。
为了处理应用在后台时未调用的 onMessageReceived,我在启动器活动中实现了重定向逻辑(通过意图包)。
但图像仍然不可见。
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
sendNotification(remoteMessage);
}
private void sendNotification(RemoteMessage remoteMessage) {
Intent intent;
if (remoteMessage != null) {
RemoteMessage.Notification notification = remoteMessage.getNotification();
intent = new Intent(this, MainActivity.class);
intent.putExtra("url", url);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, REQUEST_CODE, intent,
PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.BigPictureStyle BigPicstyle = new NotificationCompat.BigPictureStyle()
.bigPicture(bitmap_image)
.setBigContentTitle(title)
.setSummaryText(body)
.bigLargeIcon(null);
NotificationCompat.Builder notificationBuilder = null;
notificationBuilder = new NotificationCompat.Builder(this, CHANNEL_ID);
if (bitmap_image != null) {
notificationBuilder.setStyle(BigPicstyle);
notificationBuilder.setLargeIcon(bitmap_image);
} else {
notificationBuilder.setStyle(BigTextstyle);
notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
}
//region setting notification
notificationBuilder
.setContentTitle(title)
.setContentText(body)
.setPriority(Notification.PRIORITY_HIGH)
.setWhen(System.currentTimeMillis())
.setVisibility(getNotificationId())
.setChannelId(CHANNEL_ID)
.setNumber(1)
.setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL)
.setContentIntent(pendingIntent);
//endregion
getManager().notify(getNotificationId(), notificationBuilder.build());
}
}
当应用程序处于终止状态时,我会收到带有标题和正文的基本通知。当应用程序处于终止状态时,我如何获取图像???
【问题讨论】:
标签: android firebase firebase-cloud-messaging