我正在
Android中实施FCM通知,但根据应用状态(背景与前景)通知有何不同?
{ "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 here notificationmanager 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,而是显示大图.
感谢您的支持.
解决方法
原文地址:https://www.jb51.cc/android/312146.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。