Flutter FCM is not working when app is closed

4,153

Solution 1

I solved it. Basically, all I had to do was go to the app settings and in there I turned on autostart in permission and it worked like magic.

Solution 2

For those who are facing a similar problem with any device, check if the device is listed here: https://dontkillmyapp.com/

The problem is, some android manufacturers customize the system with features for battery savings that just kill our app, and prevent it from working and receiving notifications in background. Some giant apps like facebook, uber, instagram work just fine because they're usually listed in a 'whitelist'.

There isn't much we as developers can do in such scenarios, but usually there is an option on the system to allow a specific app on background. The previous link clarify these use cases.

Share:
4,153
Ashutosh Sharma
Author by

Ashutosh Sharma

I am a High-School Student with a hobbie of programming.

Updated on December 12, 2022

Comments

  • Ashutosh Sharma
    Ashutosh Sharma over 1 year

    I have been trying to make an app in Flutter that receives a push notification. When I run it on Redmi note 5 I get the notification when the app is in foreground or background but I don't get any notification when the app is terminated. On the other hand, When I run it on OnePlus 6T everything works even when the app is terminated. I think the problem here is that the app is not allowed to run in background or something but how do instagram, facebook... achieve this?

    • 10101010
      10101010 almost 5 years
      It is clear that it is working. If I am not wrong it is only not working on your redmi note 5.
    • Jawad Ahmed
      Jawad Ahmed about 4 years
      Did you found any solution
  • Ashutosh Sharma
    Ashutosh Sharma almost 5 years
    which permission to ask?
  • Saeiddjawadi
    Saeiddjawadi almost 5 years
  • Ashutosh Sharma
    Ashutosh Sharma almost 5 years
    That can be a user side solution I need solution as a developer
  • Saeiddjawadi
    Saeiddjawadi almost 5 years
    use this permission : android.permission.REQUEST_COMPANION_USE_DATA_IN_BACKGROUND another Link: developer.android.com/reference/android/… hope it help you.
  • Konstantin
    Konstantin over 3 years
    It's not a good solution. Only a few apps on my phone have this permission. The rest don't, and despite that they can receive notifications event when they are off