我无法在后台应用程序中收到任何FCM消息 [英] I cannot receive any FCM message anymore in background application

查看:208
本文介绍了我无法在后台应用程序中收到任何FCM消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的应用程序处于后台时,我无法再收到任何数据信息。
请注意,它直到最近才在我的应用程序中完美运行。也许它在我的开发环境中最近更新后停止工作,我不能说....

所以我试着用 quickstart-android项目,看看它效果更好。



而且答案是否定的!

我毫不怀疑quickstart-android项目已经配置好,可以使用FCM功能......



我从Advanced REST Client发送以下消息,我成功地使用它来测试当前发布的应用程序。

  {
to:dLN4paNl3uw:APA91bH0lpkEMxGp ...._ 7EdxkB2cRbPKFxT2Ti3OPw-7fCSwXCSfGG,
data:{
id:19,
title:标题测试,
msg:测试文本,
code:2,
},
delay_while_idle:false,
优先权:高,
content_available:true
}

我能说的是,无论何时何地当应用程序处于后台时,我发送消息,我在logcat中显示以下内容:

  07-22 12:54:21.400 14316-14316 /? W / GCM-DMM:广播意图回调:结果= CANCELED forIntent {act = com.google.android.c2dm.intent.RECEIVE flg = 0x10000000 pkg = com.google.firebase.quickstart.fcm(有额外功能)} 

所以这个消息很好的被设备接收,但是没有被传送到onMessageReceive()。



我看到很多关于这个问题的文章,但答案总是含糊不清,因为我们可以说它适用于某些人,而不适用于其他人。
所以我想知道最近是否有人对这个问题找到了更准确的解释,因为我不知道它是否来自开发环境,因为我试图用新更新的工作室构建旧的工作项目,sdk ,构建工具和我面临同样的问题,GCM / FCM消息不会再由新建的应用程序接收。



编辑



经过更多调查后,我在logcat中看到,当我从最近的应用程序列表中滑出时,我的应用程序已关闭。这当然可以解释它无法处理设备收到的消息。

  07-23 23:12:29.002 671- 31254 /? I / ActivityManager:Killing 17453:com.google.firebase.quickstart.fcm / u0a297(adj 9):删除任务
07-23 23:12:29.016 14316-14524 /? D / GCM:删除Messenger 0:com.google.firebase.quickstart.fcm
07-23 23:12:29.017 671-2998 /? I / WindowState:WIN DEATH:窗口{2a27cf7 u0 com.google.firebase.quickstart.fcm / com.google.firebase.quickstart.fcm.MainActivity}
07-23 23:12:30.148 671-4851 /? I / ActivityManager:强制停止com.google.firebase.quickstart.fcm appid = 10297 user = 0:来自pid 18289



几个星期前,我还尝试了一个基于GCM 8.4.0,sdk 23,java 1.7的工作项目,该工作正在进行中,我也遇到了同样的问题;应用程序已关闭。



在我成功用于测试我的工作项目的两个不同设备上观察到:nexus 7 LTE 6.0.1和GT-9295 5.0.1 <
我现在看到的唯一区别是Android Studio / gradle的版本。工作项目使用1.5.2构建,现在我使用2.1.2,我无法再构建任何工作应用程序。

我在2台不同的计算机上遇到了这个问题,其中一台计算机重新安装了所有设备!

解决方案

FCM有两种类型的通知静音和非静音: -

无声通知: - 您始终会在 onMessageReceived 方法中获得回叫


$ b

strong>: - 当应用在前台时,您在 onMessageReceived 方法中获得回调,但当应用在后台时,FCM会在通知栏中生成默认通知。

在FCM中,只有数据部分的通知被视为无声通知。



你传递一个JSON对象,如下所示: - $ / $>

  {
notification:{
title :测试通知,
body:通知已发送!,
声音:呼叫,
图标:ic_app_icon
} ,
data:{
someData:Great
},
to:app_token,
priority:high

$ / code>

如果您想发送无声通知从服务器那么结构应该是这样的: - $ / b>

  {
data:{
someData:Great
},
to:app_token,
priority:high
}



正如你可以看到的那样,它只是没有通知对象的有效载荷。


I cannot receive any data message anymore in my application when it's in background. Notice that it worked perfectly in my application until very recently. Maybe it stopped working after recent updates in my development environment, I can't say....

So I tried to make the test with the quickstart-android project, to see it works better.

And the answer is no!

I have no doubt that quickstart-android project is well configured to use FCM capabilities...

I send the following message from Advanced REST Client, I used it successfully to test my application currently published.

{
  "to" : "dLN4paNl3uw:APA91bH0lpkEMxGp...._7EdxkB2cRbPKFxT2Ti3OPw-7fCSwXCSfGG",
  "data": {
    "id": 19,
    "title": "Title test",
    "msg": "Text of the test",
    "code": 2,
  },
  "delay_while_idle" : false,
  "priority" : "high",
  "content_available" : true
}

What I can say is that when and every time I send a message while the application is in background, I get the following display in logcat

07-22 12:54:21.400 14316-14316/? W/GCM-DMM: broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000000 pkg=com.google.firebase.quickstart.fcm (has extras) }

So the message is well received by the device but not transferred to onMessageReceive().

I saw many posts about such problem but the answers are always vague as what we can say is that it work for some and don't work for some others. So I'd like to know if someone recently found a more precise explanation to this problem because I wonder if it couldn't come from the development environment as I tried to build older working project with the newly updated studio, sdk, build tools and I face the same problem, GCM/FCM messages are not received anymore by the newly built application.

EDIT

After more investigations, I saw in logcat that my application is force closed when I swipe it out from the recent apps list. This certainly explain it cannot be able to handle the message received by the device.

07-23 23:12:29.002 671-31254/? I/ActivityManager: Killing 17453:com.google.firebase.quickstart.fcm/u0a297 (adj 9): remove task
07-23 23:12:29.016 14316-14524/? D/GCM: Removing messenger 0:com.google.firebase.quickstart.fcm
07-23 23:12:29.017 671-2998/? I/WindowState: WIN DEATH: Window{2a27cf7 u0 com.google.firebase.quickstart.fcm/com.google.firebase.quickstart.fcm.MainActivity}
07-23 23:12:30.148 671-4851/? I/ActivityManager: Force stopping com.google.firebase.quickstart.fcm appid=10297 user=0: from pid 18289

I also tried a working project of mine built few weeks ago, based on GCM 8.4.0, sdk 23, java 1.7, which was working and I get the same problem; Application is force closed.

This is observed on 2 different devices I successfully used to test my working project: nexus 7 LTE 6.0.1 and GT-9295 5.0.1
The only difference I see now is the version of Android Studio/gradle. Working project were built with 1.5.2 and now I use 2.1.2, I cannot build any working application anymore.
I get this problem on 2 different computers and on one of them I reinstalled everything!

解决方案

FCM have two type of notification Silent and Non-Silent:-

Silent notification :- You always get callback in onMessageReceived method

Non-Silent Notification :- When app is in foreground you got a callback in onMessageReceived method but when app is in background FCM generate a default notification in notification bar.

A notification with only data part is treated as silent notification in FCM.

When you generate notification from server you pass a JSON object something like that :-

{
  "notification":{
    "title":"Test Notification",
    "body":"Notification is delivered!",
    "sound":"call",
    "icon": "ic_app_icon"
  },
  "data":{
    "someData":"Great"
  },
  "to": "app_token",
  "priority":"high"
}

The above one is a Non-Silent notification if you want to send silent notification from server then the structure should be something like that :-

{
  "data":{
    "someData":"Great"
  },
  "to": "app_token",
  "priority":"high"
}

As you can it is the same structure just without notification object in payload.

这篇关于我无法在后台应用程序中收到任何FCM消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆