4

I am using this tutorial to implement push notifications using Firebase, but I cannot seem to figure it out. Keeps throwing the error:

FirebaseInstanceId: background sync failed: SERVICE_NOT_AVAILABLE, retry in 40s

I am created a class extending FirebaseMessagingService and onMessageReceived(..). I receive the data. I registered the service in the manifest like:

 <!-- [START firebase_service] -->
        <service android:name="notifications.MyFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
        <!-- [END firebase_service] -->

I added latest google-services.json in the root folder of my app. Still, I log nothing.

Naturally, I scoured into StackOverflow to check similar problems. Not many, apparently. Found this, but wasn't very helpful as I still got the same message sent. Any thoughts on something I could have missed?

I tried checking if my device has PlayStore services running and indeed it has:

  public boolean isGooglePlayServicesAvailable() {
        GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
        int status = googleApiAvailability.isGooglePlayServicesAvailable(getApplicationContext());
        if (status != ConnectionResult.SUCCESS) {
            if (googleApiAvailability.isUserResolvableError(status)) {
                googleApiAvailability.getErrorDialog(MainActivity.this, status, 2404).show();
            }
            return false;
        }
        return true;
    }
Community
  • 1
  • 1
Steve Kamau
  • 2,755
  • 10
  • 42
  • 73
  • 1
    Try this ink , it might be helpful for you http://stackoverflow.com/questions/40561289/fcm-integration-getting-the-exception – Ravindra Kushwaha Jan 19 '17 at 10:22
  • 1
    If you are running it on an emulator, then Firebase won't run without Google Play Services, so check if that is available. – harshithdwivedi Jan 19 '17 at 10:24
  • @HarshitDwivedi I am not running on an emulator, see my edit – Steve Kamau Jan 19 '17 at 10:30
  • @RavindraKushwaha i tried also by moving my class into the root package but still error – Steve Kamau Jan 19 '17 at 10:34
  • 1
    Hi Steve. SERVICE_NOT_AVAILABLE is an error not really caused by Firebase. This is often an issue with the device's connectivity, commonly unable to connect to the FCM service. Have you tried testing with an emulator or a different device connected to a stable connection? See if it still shows the same error? – AL. Jan 19 '17 at 10:42
  • @AL. But the same device can open web pages as well as receive Whatsapp messages. On emulator it doesn't work because I haven't installed playstore services on it. – Steve Kamau Jan 19 '17 at 11:03
  • That is odd. Have you tried with a different device though? For the emulator, you just have to download the emulator image with Google Play Services. – AL. Jan 19 '17 at 11:06
  • 1
    @SteveKamau what is your device make and model and version of Google Play Services installed on your device? For firebase to work properly, it needs the google play services running in the background. So make sure that it is installed and running. – harshithdwivedi Jan 19 '17 at 12:18

2 Answers2

7

Thanks guys, i was able to fix the issue by simply enabling Google playstore services in my phone's Settings > Data plan

Steve Kamau
  • 2,755
  • 10
  • 42
  • 73
1

I had the same problem. I have found that the problem was with my mobile operator Internet Service. I simply installed A third party VPN app (from Google Play Store) to unblock Google Services.

smnadim21
  • 57
  • 4
  • Sorry, can you explain a little bit more about this? I'm running into the same problem. What did you tell them? – 4gus71n Jan 03 '19 at 14:54
  • this problem is caused by your network service provider, if you are using your Android phone.. download Turbo VPN or Hotspot Sheild to change the state of your network... i hope error will be gone – smnadim21 Jan 04 '19 at 16:26
  • Oh okay, sorry I misunderstood your question; I thought that you were saying that you were using a VPN service on your network and that was blocking the Google Services requests. That's my case, and I'm trying to figure out what to tell the IT department about what url they should whitelist. – 4gus71n Jan 04 '19 at 17:17