这是我的清单
<service android:name=".fcm.PshycoFirebaseMessagingServices">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name=".fcm.PshycoFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)
当应用程序处于后台并且通知到达时,默认通知将会运行并且不会运行我的代码onMessageReceived.
这是我的onMessageReceived代码.如果我的应用程序在前台运行,而不是在后台应用程序时,则调用此方法.如何在应用程序处于后台时运行此代码?
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO(developer): Handle FCM messages here.
// If the application is in the foreground handle both data and notification messages here.
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Postman测试FCM,但即使FCM令牌存在,我总是会收到以下错误.我在Cloud Messaging选项卡中获得了令牌:Firebase Cloud Messaging令牌.
<HTML>
<HEAD>
<TITLE>The request was missing an Authentification Key (FCM Token). Please, refer to section "Authentification" of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.</TITLE>
</HEAD>
Run Code Online (Sandbox Code Playgroud)
这是我发送的内容.
POST /fcm/send HTTP/1.1
Host: fcm.googleapis.com
Cache-Control: no-cache
Postman-Token: 9109eb13-245f-0786-21a5-6207f5426b44
Content-Type:application/json
Authorization:key=AAAAfnYrKvU:APA91bFwgeM3zuFId6UDzvIHk9qZ3lKHnX-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
{ "data": { "message": "This is a Firebase Cloud Messaging Topic Message!", } }:
Run Code Online (Sandbox Code Playgroud) 在Firebase控制台中,我看到了使用app"com.example"(其中com.example是应用名称)向User Segement发送通知的选项.
如图所示:
但是如何使用FCM REST API从服务器端执行此操作:
我正在尝试通过Postman使用Firebase Cloud Messaging发送测试通知。我正在对此网址进行POST
https://fcm.googleapis.com/v1/projects/[my project name]/messages:send
Run Code Online (Sandbox Code Playgroud)
邮递员中的“授权”选项卡设置为“无身份验证”,“我的标题”选项卡如下所示
Content-Type: application/json
Authorization: Bearer [server key]
Run Code Online (Sandbox Code Playgroud)
[服务器密钥]是Firebase项目“设置”区域中“云消息”标签中的新生成的服务器密钥。我不断收到此错误作为回应。
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}
Run Code Online (Sandbox Code Playgroud)
根据我能找到的所有信息,我使用了正确的令牌,但Google似乎不同意。我应该发送什么作为Authorization标头来克服此错误?
我正在尝试使用Firebase实施通知.当应用程序位于后台或前台时,会正确接收通知.所以,基本机制正在发挥作用.
现在我已将Content Extensions和Service Extensions添加到应用程序中.内容扩展在我使用本地通知时有效,但只要考虑可选字段,Firebase消息有效内容就会显示不正确.这是我的控制台图像的链接:

以下是Firebase远程通知有效负载(为了匿名而编辑了一些长Google数据:
{
aps =
{
alert =
{
body = "Eureka! 11";
title = "Patient is not doing well";
};
};
category = provider-body-panel;
gcm.message_id = 0:149073;
gcm.n.e = 1;
google.c.a.c_id = 2825604;
google.c.a.e = 1;
google.c.a.ts = 149073;
google.c.a.udt = 0;
mutable-content = 1;
}
Run Code Online (Sandbox Code Playgroud)
似乎"类别"和"可变内容"不在正确的位置.它们应该在aps有效载荷中.
如何让这些选项在有效负载中,以便我的应用程序可以正确解析它并将其与内容和服务扩展连接?
apple-push-notifications ios firebase firebase-cloud-messaging
所以我目前正在开发一个PWA.
我现在正在使用推送通知,我已经能够通过以下非常简单的JSON结构接收背景和前景通知.
{
"message":{
"token":"aValidToken",
"notification": {
"title": "New Content!",
"body": "A new video has been uploaded."
}
}
}
Run Code Online (Sandbox Code Playgroud)
我还能够在其中添加包含其他信息的数据成员,并且仍然可以获得通知而不会带来任何不便.
现在的问题是,如果我想将另一个成员添加到JSON,例如click_action,我发布以下内容:
{
"message":{
"token":"aValidToken",
"notification": {
"title": "New Content!",
"body": "A new video has been uploaded.",
"click_action":"https://www.google.com.ar/"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"click_action\" at 'message.notification': Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "message.notification",
"description": "Invalid …Run Code Online (Sandbox Code Playgroud) json push-notification service-worker progressive-web-apps firebase-cloud-messaging
无法弄清楚如何在 aps 字典中发送 mutable_content=true 。这是我从 firebase 消息控制台发送通知时收到的 json 有效负载
{
aps = {
alert = {
body = "50% off on booking ";
title = "CompanyName 50% coupon ABC50OFF";
};
sound = default;
};
"attachment-url" = "https://www.xxxxxxxxx.com/campaign/images_thumb/Toyota-Fortuner-AT.jpg";
"click_action" = reminder;
"content_available" = 1;
"gcm.message_id" = "0:1491225835295720%a84b45aaa84b45aa";
"gcm.n.e" = 1;
"gcm.notification.sound2" = default;
"google.c.a.c_id" = 3829383583613273032;
"google.c.a.e" = 1;
"google.c.a.ts" = 1491225835;
"google.c.a.udt" = 0;
"mutable_content" = 1;
}
Run Code Online (Sandbox Code Playgroud) ios firebase firebase-cloud-messaging firebase-notifications