Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GcmNetworkManager scheduling issues

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+.

like image 571
user2662821 Avatar asked Apr 27 '16 08:04

user2662821


People also ask

What is gcmnetworkmanager in Android Studio?

public class GcmNetworkManager extends Object. Class to create apps with robust "send-to-sync", which is the mechanism to sync data with servers where new information is available. You can use the API to schedule network-oriented tasks, and let Google Play services batch network operations across the system.

What happened to gcmnetworkmanagerextends?

public class GcmNetworkManagerextends Object This class is deprecated. As of November 1, 2020, GCMNetworkManager client libraries are no longer supported. GCMNetworkManager API calls no longer work on devices running Android M and later once your app targets future Android versions ( > Android 10).

Can I use workmanager instead of gcmnetworkmanager to schedule background jobs?

This document explains how to migrate apps to use the WorkManager client library to perform background operations instead of the GCMNetworkManager library. The preferred way for an app to schedule background jobs is to use WorkManager.

How do I use GCM in workmanager?

By also including the WorkManager GCM library, you can enable WorkManager to use GCM to schedule the tasks when running on Android devices running API level 22 or lower. If your app currently uses GCMNetworkManager to perform background operations, follow these steps to migrate to WorkManager.


1 Answers

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.

like image 153
inkedTechie Avatar answered Sep 17 '22 15:09

inkedTechie