我正在使用FCM API与邮递员发送通知,这是通知结构:
{ "notification": { "Title": "Notification Title","body": "Notification message","sound": "default","color": "#53c4bc","click_action": "MY_BOOK","icon": "ic_launcher" },"data": { "main_picture": "URL_OF_THE_IMAGE" },"to" : "USER_FCM_TOKEN"}
要渲染的图像取自data.main_picture.
我已经实现了我自己的FirebaseMessagingService,它使通知在前台状态下完美显示.通知代码是下一个:
NotificationCompat.BigPictureStyle notiStyle = new NotificationCompat.BigPictureStyle();notiStyle.setSummaryText(messageBody);notiStyle.bigPicture(picture);Uri defaultSoundUri= ringtoneManager.getDefaultUri(ringtoneManager.TYPE_NOTIFICATION);NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this) .setSmallicon(R.drawable.ic_launcher) .setLargeIcon(bigIcon) .setContentTitle(Title) .setContentText(messageBody) .setautoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent) .setStyle(notiStyle); code herenotificationmanager notificationmanager = (notificationmanager) getSystemService(Context.NOTIFICATION_SERVICE);notificationmanager.notify(0,notificationBuilder.build());
但是,在后台,服务甚至不执行.在AndroIDManifest.xml中,Firebase服务的声明如下:
<service androID:name=".MyFirebaseMessagingService"> <intent-filter> <action androID:name="com.Google.firebase.MESSAGING_EVENT"/> </intent-filter></service><service androID:name=".MyFirebaseInstanceIDService"> <intent-filter> <action androID:name="com.Google.firebase.INSTANCE_ID_EVENT"/> </intent-filter></service>
我的问题不是LargeIcon或Smallicon,而是显示大图.
感谢您的支持.
解决方法 FCM通知消息不支持largeIcon或bigPicture.如果您在后台需要它们,可以使用FCM数据消息.
对于数据消息,始终调用onMessageReceived(message)方法,因此可以使用message.getData()方法并创建自定义通知.
在这里阅读有关通知消息与数据消息的更多信息:
https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages
以上是内存溢出为你收集整理的android – Firebase展开式通知当应用程序在后台时显示图像全部内容,希望文章能够帮你解决android – Firebase展开式通知当应用程序在后台时显示图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)