dev*_*v90 5 android push-notification android-intent
我通过使用以下代码为推送通知设置大图标。
new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.logo)
.setContentTitle(notification.getTitle())
.setContentText(notification.getBody())
.setAutoCancel(true)
.setColor(getResources().getColor(R.color.green))
.setSound(defaultSoundUri)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.logo))
.setPriority(Notification.PRIORITY_MAX)
.setContentIntent(pendingIntent);
Run Code Online (Sandbox Code Playgroud)
这可以正常工作,并largeIcon在应用程序位于前景中时显示,但在应用程序不在前景中时,它不会显示大图标。
我正在测试应用程序 samsung s7(oreo)
小智 5
仅当您的应用程序位于前台时,您粘贴的代码片段才能正常工作,因为仅当应用程序位于前台时才被调用。当应用程序处于后台时,Android系统将为您显示通知(基于服务器发送到设备的JSON对象中的“ notification”对象)。根本没有呼叫您的接收器。当前,Firebase Cloud Messaging不支持将大图标设置为请求中的有效内容。
解决该问题的方法是在消息的POST负载中不包括“ notification”对象。当您仅在有效负载中包含“数据”对象时,即使您的应用程序处于后台,也会要求接收方处理通知。然后,您可以按照与应用程序在前台相同的方式构建通知,并为通知设置一个大图标。
查看此答案,以获取有关此问题的更详细说明。
尝试这个,
建议您设置默认值以自定义通知的外观。您可以指定自定义默认图标和自定义默认颜色,只要通知负载中未设置等效值,就会应用这些图标和自定义默认颜色。
在应用程序标记内添加以下行以设置自定义默认图标和自定义颜色:
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_stat_ic_notification" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
432 次 |
| 最近记录: |