问题描述
我正在将纯FCM数据通知发送到端对端加密的Android客户端。 android应用程序对数据通知有效载荷进行解密,并根据加密后的数据创建本地通知。只要应用程序在前台或后台运行,此方法就可以正常工作:接收,解密甚至在锁定屏幕上显示通知有效载荷,但前提是应用程序正在运行。我还查看了消息优先级,并在通知消息的AndroidConfig成员和数据字段中发送到FCM的应用程序服务器中将其设置为“高”,但无济于事。将数据消息发送到当前未运行相应应用的android设备的正确方法是什么?这有可能吗?
我的服务器代码(用golang表示)如下所示,希望该片段有意义:
app,err := firebase.NewApp(context.Background(),nil)
if err != nil {
logger.Info("Error initializing app: %v\n",err)
os.Exit(-536870136) /// -536870136 = 0xE0000308 is ERR_INOTE_FCM_Failed_APP_INITIALIZE
}
// Obtain a messaging.Client from the App.
ctx := context.Background()
client,err := app.Messaging(ctx)
if err != nil {
logger.Info("Error getting Messaging client: %v\n",err)
os.Exit(-536870137) /// -536870137 = 0xE0000307 is ERR_INOTE_FCM_Failed_GET_MESSAGING_CLIENT
}
message := &messaging.Message{
Data: map[string]string{
"NotificationType": "Push","E2E": strEncrypted,"IV": strIV,"Key": strSessionKey,"Signature": strSignature,},Token: registrationToken,}
// Send a message to the device corresponding to the provided
// registration token.
response,err := client.Send(ctx,message)
if err != nil {
logger.Info(err)
os.Exit(-536870138) /// -536870138 = 0xE0000306 is ERR_INOTE_FCM_Failed_SEND
}
任何帮助表示赞赏,
- 斯蒂芬
解决方法
您做得很好,而且绝对正确 当后台应用程序不再处理消息时,它是android操作系统的行为
您需要在Android清单文件中添加默认的意图过滤器,并且当应用程序在后台运行时是否出现通知。因此,单击fcm后,您将启动默认活动。 在这里您可以添加逻辑