Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在应用程序未运行时发布加载资源_Android_Firebase_Android Notifications_Firebase Cloud Messaging_Firebase Notifications - Fatal编程技术网

Android 在应用程序未运行时发布加载资源

Android 在应用程序未运行时发布加载资源,android,firebase,android-notifications,firebase-cloud-messaging,firebase-notifications,Android,Firebase,Android Notifications,Firebase Cloud Messaging,Firebase Notifications,我发现android通知上的小图标也存在类似问题,但谷歌不会给我任何关于以下问题的提示: 简而言之,当应用程序未打开时,我的通知不会显示颜色和图标,但当应用程序在屏幕上可见时,我的通知会完美工作 出现通知时,应用程序正在后台运行: 出现通知时,应用程序在屏幕上可见: 对我来说,该服务似乎无法使用其当前上下文加载某些资源。目前,我正在使用自己的python服务器调用firebase REST Api来发送通知 虽然标题和正文直接通过通知自身的有效负载发送,但图标和颜色由应用程序选择 这就是在服

我发现android通知上的小图标也存在类似问题,但谷歌不会给我任何关于以下问题的提示:

简而言之,当应用程序未打开时,我的通知不会显示颜色和图标,但当应用程序在屏幕上可见时,我的通知会完美工作

出现通知时,应用程序正在后台运行:

出现通知时,应用程序在屏幕上可见:

对我来说,该服务似乎无法使用其当前上下文加载某些资源。目前,我正在使用自己的python服务器调用firebase REST Api来发送通知

虽然标题和正文直接通过通知自身的有效负载发送,但图标和颜色由应用程序选择

这就是在服务中构建通知的方式

final Context context = this.getApplicationContext();

final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                .setDefaults(Notification.DEFAULT_SOUND)
                .setContentTitle(notification.getTitle())
                .setContentText(notification.getBody())
                .setColor(ContextCompat.getColor(context, R.color.notification))
                .setSmallIcon(R.drawable.ic_local_shipping_white_24dp);
这是最终显示通知的片段:

final NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(context);
final boolean notificationsEnabled = mNotificationManager.areNotificationsEnabled();
if (notificationsEnabled) {
    mNotificationManager.notify(notifyID, mBuilder.build());
}
我感谢你的帮助

您可以尝试:

1.更新至9.8.0版并检查解决方案

2. 设置发送推送通知时的图标和颜色

JSON示例:

{
     "notification" : {
      "body" : "My amazing body!",
      "title" : "My amazing title",
      "icon" : "ic_logo",
      "sound" : "default",
      "color" : "#D63A49"
    },
    "registration_ids": ["XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"]
}
{
    "data": {
        "my_custom_key" : "my_custom_value",
        "whatever" : "YES",
        "other_key" : true
     },
    "to": "XXXXXXX"
}
ic_logo是资源名称

3.发送
数据
通知。这样,即使应用程序处于backgrdound状态,也会调用
onMessageReceived(RemoteMessage message)
方法

JSON示例:

{
     "notification" : {
      "body" : "My amazing body!",
      "title" : "My amazing title",
      "icon" : "ic_logo",
      "sound" : "default",
      "color" : "#D63A49"
    },
    "registration_ids": ["XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"]
}
{
    "data": {
        "my_custom_key" : "my_custom_value",
        "whatever" : "YES",
        "other_key" : true
     },
    "to": "XXXXXXX"
}

如果您使用firebase推送通知工具测试推送,则推送可能会重复,因为如果您的应用程序在后台模式下收到通知,则此通知将按系统管理,系统将显示您的应用程序图标,这就是为什么您的应用程序未正确显示的原因notification@Manza我试着把它添加到清单上,但还是不行。因为我还想决定动态使用哪个图标,这可能是另一个用例。我确实经常读到,它必须是透明的白色图标,我也可以验证我目前使用的材质图标。@TheWhiteLlama我链接的解决方案适用于firebase 9.8.0版。或者检查我的答案below@TheWhiteLlama我已经更新了答案好的,我会试试这个。有一个问题仍在我脑海中:如何设置小图标,但只设置资源名称?资源名称是可绘制文件夹中的图标:),那么如何设置图标P setSmallIcon方法仅接受您正在执行的int参数。setSmallIcon(R.drawable.ic_local_shipping_white_24dp);啊,现在它工作了。你太棒了!那么当应用程序在后台运行时,firebase将自行选择正确的图标?非常感谢你!