Android Oreo battery optimization causes delays in FCM

I implemented FCM in the same way as the documentation if it says:

I have such a service public class TCMessagingService extends FirebaseMessagingService

And I declared it in the manifest like this:

<service android:name=".services.TCMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
</service>

I am targeting and compiling with an SDK level of 25, and my version of firebase is 10.2.1.

Now the problem is that on Android 8.0 sometimes I have big delays when I receive push notifications. it may come in a few minutes. But this is not always the case, sometimes everything works the same as expected, push notifications arrived very quickly.

I tried updating the FCM version to the latest, but that didn't help.

But when in the settings I turn off battery optimization for my application, everything works fine. But this is not a solution. What can I do to make FCM work expected on Android 8.0?

+4
3

.

push- Android 8, compileSdkVersion 25

classpath 'com.google.gms:google-services:3.1.0' 

gradle.

, , -

+1

, . , FCM "".

Firebase FCM .

+1

:

  • 26
  • 26.0.2
  • google: 11.0.4

  • :

    compile 'com.firebase: firebase-jobdispatcher: 0.5.2'

  • firebase :

    classpath 'com.google.gms: google-services: 3.1.0'

  • google gradle

    allprojects {repositories {Google () jcenter ()}}

  • In your java track, the notification manager is created in a different way in Android O:

          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
             NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
             String id = "id_product";
             // The user-visible name of the channel.
             CharSequence name = "Product";
             // The user-visible description of the channel.
             String description = "Notifications regarding our products";
             int importance = NotificationManager.IMPORTANCE_MAX;
             NotificationChannel mChannel = new NotificationChannel(id, name, importance);
             // Configure the notification channel.
             mChannel.setDescription(description);
             mChannel.enableLights(true);
             // Sets the notification light color for notifications posted to this
             // channel, if the device supports this feature.
             mChannel.setLightColor(Color.RED);
             notificationManager.createNotificationChannel(mChannel);
          }
    

You can find the full code in this link .

+1
source

Source: https://habr.com/ru/post/1685854/


All Articles