繁体   English   中英

当app在后台使用firebase notifiaction时如何在android中显示BigPictureStyle Notification?

[英]how to show BigPictureStyle Notification in android when app is in background while using firebase notifiaction?

我正在使用firebase通知。 当app处于前台时onMessageReceived被调用,并且通知与图像可见(BigPictureStyle通知)。 但是当app处于被杀死状态时,不会调用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());

        }


    }

应用程序处于被杀死状态时,我会收到标题和正文的基本通知。 当应用程序处于被杀死状态时,我怎样才能获得图像?

使用您希望在通知中显示的固定大小的图像,如下所示(图片不应为多种尺寸)

         setLargeIcon(largeIcon);  // access it from drawable folder.

不要在mipmap文件夹中使用图像。 它给出了合适的分辨率图像。 在清单文件中做同样的事情......

<meta-data
    android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@drawable/notification_icon_of_fixed_sized" />
<meta-data 
    android:name="com.google.firebase.messaging.default_notification_color"
    android:resource="@color/google_blue" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM