Android应用程序从最近的列表中滑过时,不会调用Android Firebase MyFirebaseMessagingService [英] Android Firebase MyFirebaseMessagingService not called when app is swiped from recent list

查看:1031
本文介绍了Android应用程序从最近的列表中滑过时,不会调用Android Firebase MyFirebaseMessagingService的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑24/11/2016:
我刚收到来自Firebase支持部门的消息。他们建议这是一个华硕问题。我正在使用的设备是华硕ZenFone 2激光。这里是他们的回应:


这里的问题是,Google不控制制造商
如何定制他们的android版本。如果华硕遵循Android
准则,那么通知应该可以工作(就像其他的
设备一样)。

我们发现的一件事是有些手机把应用程序强制停止
状态,这阻止了应用程序接收通知。

从您的测试结果,这似乎并不是这样的。但有许多其他的方式,其中华硕可以停止通知工作,
不幸的是我们无法检查所有这些。



这将是最好给你联系华硕支持,让我们知道如果
有任何消息。

因为这是一个低优先级问题给我的客户,我现在不打算进一步追求。我不幸没有时间在其他设备上测试相同的问题。如果将来发生变化,我会更新这个问题。到现在为止,我会考虑这个未解决的。我有兴趣听听其他品牌手机是否有相同的问题。



至于华硕用户,有一点需要考虑:有省电设置,禁用通知。



编辑30/09/2016:
我已经就此问题与Firebase支持部门联系了。他们似乎同意Arthur Thompson的说法:


  • 已停止的应用程序不应收到消息。


  • $ b $刷新最近列表中的应用程序应
  • 停止应用程序。 b

    有趣的部分是,我的应用程序似乎并没有停止。运行 adb shell dumpsys包|时grep停止我的包返回:

      User 0:installed = true hidden = false stopped = false notLaunched = false enabled = 0 

    这表示它没有停止,应该仍然收到消息(根据非常有用的信息Firebase支持工程师)。然而,该应用程序没有收到消息。

    编辑27/09/2016:
    我省略了通知对象,并移动那个信息来完成 data 对象。这并不能解决问题。我觉得问题不清楚。问题是,当应用程序被杀害(最近刷新)该服务不会被调用或接收通知了。



    原始邮件



    有类似的帖子,但没有解决这个问题或提供解决方案。

    我正在执行FCM以获取通知。 (我在FCM上相当新颖)。消息有效载荷是通知数据的组合。当应用程序处于前台时,服务会触发 onMessageReceived()。当应用程序在后台(即我按主页按钮)时, onMessageReceived()不会触发(按预期),只是显示通知。我仍然可以看到 MyFirebaseMessagingService.onCreate() onDestroy()上的日志语句,现在,当我通过按最近的应用程序按钮关闭应用程序,并将应用程序从列表中划出时,我不再收到任何通知。 onCreate() onDestroy()不再被调用。没有通知出现。





      {
    to:token,
    priority:high,
    notification:{
    body:hello,
    title:Mom from Mom,
    click_action:ACTIVITY_MAIN
    },
    data:{
    open:chat

    }

    FCM服务:

      public class MyFirebaseMessagingService extends FirebaseMessagingService {
    $ b @Override
    public void onCreate(){
    super.onCreate ();
    Log.v(DmcApplication.TAG,创建服务);


    @Override
    public void onDestroy(){
    super.onDestroy();
    Log.v(DmcApplication.TAG,Service Destroyed ...);

    $ b @Override
    public void onMessageReceived(RemoteMessage remoteMessage){
    Log.v(DmcApplication.TAG,Message received!);
    EventBus.getDefault()。post(new MessageEvent(remoteMessage.getNotification()。getBody()));
    }

    }

    相关)

    pre $ lt; code>< service
    android:name =com.example.package.myFirebaseMessagingService
    机器人:导出= 假 >
    < intent-filter>
    < action android:name =com.google.firebase.MESSAGING_EVENT/>
    < / intent-filter>
    < / service>

    记录:

      //当应用程序处于前台并且消息进入时记录:
    V / coo:服务创建
    V / coo:收到消息!
    V / coo:服务被销毁...

    //当应用程序在后台并且消息进入时记录日志:
    V / coo:服务创建
    V / coo:服务已销毁...

    //记录应用程序被杀死的时间:
    < silence ...>

    任何帮助将不胜感激,因为我一直坚持这几天。 >

    解决方案

    我遇到了同样的问题,看着你的优先级:高字符串,它看起来像你发送到Android和iOS。我最终摆脱了消息的通知部分,只是将所需的信息放入数据消息中。数据有效负载部分即使在后台运行或从最近的应用程序中删除时也会触发您的服务。



    在我的服务器上,我检查用户是否从iOS设备或Android设备注册了令牌,并相应地发送有关iOS设备的通知有效负载Android设备的数据有效负载。

    Edit 24/11/2016: I've just received word from Firebase Support. They suggest this is an Asus issue. The device I'm using is an Asus ZenFone 2 Laser. Here's their response:

    The issue here is that Google does not control how manufacturers customize their version of android. If Asus is following the Android guidelines, then the notification should work (like on the other devices).

    One thing that we found is that some phones put the apps in force-stop state, which prevents the app from receiving the notification.

    From your test result this doesn't seems to be the case. BUT there are many other ways in which Asus can stop notifications from working, and unfortunately we cannot check all of them.

    It would be best for you to contact Asus support and let us know if there are any news.

    As this is a low priority issue for my client, I'm not going to pursue it further at the moment. I unfortunately don't have the time to test the same issue on other devices. If this changes in the future and I'll update this issue accirdingly. Until now, I will consider this unsolved. I would be interested to hear if others are having the same issues on other brand phones.

    As for Asus users, there's one thing to consider: There are power saving settings that disable notificaitons.

    Edit 30/09/2016: I've contacted Firebase support about this issue. They seem to agree with what Arthur Thompson is saying:

    • Stopped apps should not receive messages.
    • Swiping an app from the recent list should not stop an app.

    The interesting part is that my app doesn't seem to be stopped. When running adb shell dumpsys package | grep stopped my package returns:

    User 0:  installed=true hidden=false stopped=false notLaunched=false enabled=0
    

    This indicates it's not stopped and should still receive messages (according to the very helpful Firebase Support engineer). However the app is not receiving the messages.

    Edit 27/09/2016: I've omitted the notification object in the payload and moved that information do the data object instead. This doesn't solve the issue. I think I haven't been clear enough on what the issue is. The issue is that when the app is killed (swiped out of recent) the service doesn't get called or receive notifications anymore.

    Original post

    There's similar posts out there, but none that address this issue or give a solution.

    I'm implementing FCM to get notifications. (I'm fairly new at FCM.) The message payload is a combo of both notification and data. When the app is in the foreground the service fires the onMessageReceived(). When the app is in the background (i.e. I push the home button), onMessageReceived() doesn't fire (as expected) but simply shows a notification. I can still see the log statements on MyFirebaseMessagingService.onCreate() and onDestroy(), which is great.

    Now when I close the app by pushing the 'recent apps' button, and swiping the app out of the list, I no longer receive any notifications. onCreate() and onDestroy() are no longer called. No notification appears. I would like a notification to appear in this scenario too.

    Example payload:

    {
        "to":"token",
        "priority":"high",
        "notification": {
            "body":"hello",
            "title":"Message from Mom",
            "click_action":"ACTIVITY_MAIN"
        },
        "data":{
            "open":"chat"
        }
    }
    

    FCM Service:

    public class MyFirebaseMessagingService extends FirebaseMessagingService {
    
        @Override
        public void onCreate() {
            super.onCreate();
            Log.v(DmcApplication.TAG, "Service Created");
        }
    
        @Override
        public void onDestroy() {
            super.onDestroy();
            Log.v(DmcApplication.TAG, "Service Destroyed...");
        }
    
        @Override
        public void onMessageReceived(RemoteMessage remoteMessage) {
            Log.v(DmcApplication.TAG, "Message received!");
            EventBus.getDefault().post(new MessageEvent(remoteMessage.getNotification().getBody()));
        }
    
    }
    

    Bit of the manifest (in case relevant)

    <service
        android:name="com.example.package.myFirebaseMessagingService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
    

    Logs:

    //Log when app is in foreground and message comes in:
    V/coo: Service Created
    V/coo: Message received!
    V/coo: Service Destroyed...
    
    //Log when app is in background and message comes in:
    V/coo: Service Created
    V/coo: Service Destroyed...
    
    //Log when app is killed:
    <silence...>
    

    Any help would be greatly appreciated as I've been stuck with this for days now.

    解决方案

    I ran into the same issue, looking at your "priority:high" string it looks like you are sending to Android and iOS. I ended up getting rid of the notification portion of the message and just putting the information that I needed into the data message. The data payload part triggers your service even when it is backgrounded or removed from recent apps.

    On my server I check to see if the user registered their token from an iOS device or an Android device and send out the payload accordingly with the notification payload for iOS devices and the data payload for Android devices.

    这篇关于Android应用程序从最近的列表中滑过时,不会调用Android Firebase MyFirebaseMessagingService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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