GcmNetworkManager scheduling issues

2.4k views Asked by At

I am using GcmNetworkManager in my application for periodic and one of task task execution. I am getting these 2 errors and unable to figure out the reason. Implementation is correct as i am unable to reproduce these issue on staging.

Fatal Exception: java.lang.RuntimeException: Package manager has died
   at android.app.ApplicationPackageManager.queryIntentServicesAsUser(ApplicationPackageManager.java:700)
   at android.app.ApplicationPackageManager.queryIntentServices(ApplicationPackageManager.java:706)
   at com.google.android.gms.gcm.GcmNetworkManager.zzdi(Unknown Source)
   at com.google.android.gms.gcm.GcmNetworkManager.schedule(Unknown Source)

&

Caused by java.lang.IllegalArgumentException: There is no GcmTaskService component registered within this package. Have you extended GcmTaskService correctly?
   at com.google.android.gms.common.internal.zzx.zzb(Unknown Source)
   at com.google.android.gms.gcm.GcmNetworkManager.zzdi(Unknown Source)
   at com.google.android.gms.gcm.GcmNetworkManager.schedule(Unknown Source)

Any help will be appreciated.

Thanks

P.S: Devices has play-service 8.1+.

4

There are 4 answers

0
inkedTechie On

I ran across the same issue. I have found a fix, but I'm not sure about the reason why. In your AndroidManifest.xml don't forget to set enabled = true I know this a little weird, but like I said, it started working and now, the periodic task is also running successfully.

 <service
        android:name=".periodic.PeriodicTaskService"
        android:enabled="true"
        android:exported="true"
        android:permission="com.google.android.gms.permission.BIND_NETWORK_TASK_SERVICE">
        <intent-filter>
            <action android:name="com.google.android.gms.gcm.ACTION_TASK_READY" />
        </intent-filter>
    </service>

here, PeriodicTaskService obviously, extends GcmTaskService.

0
Mrigank On

1.) Have you declared your service in your manifest file like this:

<service android:name="MyTaskService"
          android:permission="com.google.android.gms.permission.BIND_NETWORK_TASK_SERVICE"
          android:exported="true">
          <intent-filter>
              <action android:name="com.google.android.gms.gcm.ACTION_TASK_READY"/>
          </intent-filter>
 </service>

Make sure you have included the permission BIND_NETWORK_TASK_SERVICE

2) Make sure your service is extending GcmTaskService and it is implementing onRunTask.

Refer: https://developers.google.com/android/reference/com/google/android/gms/gcm/GcmTaskService

0
CorayThan On

If it is failing in Robolectric tests, that is because GcmNetworkManager.getInstance(applicationContext).schedule(task) will fail in Robolectric.

0
Michael D On

Had the same issue, fixed it (after some long searching and trial and error) in my manifest file by moving the <service> xml element to within the <application> element. Perhaps this helps.

So the manifest looked like this when I had the error:

<service>
....
</service>
<application>
....
</application>

And it was fixed when I made it:

<application>
....
  <service>
  ....
  </service>
</application>