SkygearIO / skygear-SDK-Android

Skygear Android SDK

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Follow the guides to setup push notification fail to get message in onMessageReceived when user is inside the application

carmenlau opened this issue · comments

Android SDK: 1.5.0

Setup notification guides: https://docs.skygear.io/guides/push-notifications/basics/android/

User report

Push notifications are properly received when the app is in background, however if the app is currently active - no messages will be received with the following warning messages being thrown:

Key google.sent_time expected String but value was a java.lang.Long.  The default value <null> was returned.
Attempt to cast generated internal exception:
             java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
                 at android.os.BaseBundle.getString(BaseBundle.java:1089)
                 at com.google.android.gms.gcm.zza.zzr(Unknown Source:25)
                 at com.google.android.gms.gcm.GcmListenerService.handleIntent(Unknown Source:201)
                 at com.google.firebase.iid.zzg.run(Unknown Source:29)
                 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                 at java.lang.Thread.run(Thread.java:764)
Key google.ttl expected String but value was a java.lang.Integer.  The default value <null> was returned.
Attempt to cast generated internal exception:
             java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
                 at android.os.BaseBundle.getString(BaseBundle.java:1089)
                 at com.google.android.gms.gcm.zza.zzr(Unknown Source:25)
                 at com.google.android.gms.gcm.GcmListenerService.handleIntent(Unknown Source:201)
                 at com.google.firebase.iid.zzg.run(Unknown Source:29)
                 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                 at java.lang.Thread.run(Thread.java:764)

In the above attempt, a MyGcmListenerService which extends GcmListenerService() was implemented in order to handle incoming push notifications under an overridden onMessageReceived() method when the app is on. (edited)

I then followed the doc at firebase.com, implemented a customised FirebaseMessagingService() and have the push notifications received and handled successfully when the app is on. In this attempt, I have removed those skygear-related configs from AndroidManifest.xml and applied some changes in my app gradle:

implementation ('io.skygear:skygear:1.5.0') {
        exclude group: 'com.google.android.gms'
    }
    
    implementation 'com.google.firebase:firebase-messaging:15.0.0'
    implementation 'com.google.android.gms:play-services-base:15.0.1'
    implementation 'com.google.android.gms:play-services-gcm:15.0.1'

According to my understanding, since GCM is now migrated to FCM, GcmListenerService is now deprecated (ref: https://developers.google.com/android/reference/com/google/android/gms/gcm/GcmListenerService) which results in the above warnings being thrown, where FirebaseMessagingService is the replacement.

Below is a dependency tree of Skygear Android SDK 1.5.0:

+--- io.skygear:skygear:1.5.0
|    +--- com.google.android.gms:play-services-base:11.4.2
|    |    +--- com.google.android.gms:play-services-basement:11.4.2
|    |    |    +--- com.android.support:support-v4:25.2.0 -> 26.1.0 (*)
|    |    |    \--- com.google.android.gms:play-services-basement-license:11.4.2
|    |    +--- com.google.android.gms:play-services-tasks:11.4.2
|    |    |    +--- com.google.android.gms:play-services-basement:11.4.2 (*)
|    |    |    \--- com.google.android.gms:play-services-tasks-license:11.4.2
|    |    \--- com.google.android.gms:play-services-base-license:11.4.2
|    +--- com.google.android.gms:play-services-gcm:11.4.2
|    |    +--- com.google.android.gms:play-services-base:11.4.2 (*)
|    |    +--- com.google.android.gms:play-services-basement:11.4.2 (*)
|    |    +--- com.google.android.gms:play-services-iid:11.4.2
|    |    |    +--- com.google.android.gms:play-services-base:11.4.2 (*)
|    |    |    +--- com.google.android.gms:play-services-basement:11.4.2 (*)
|    |    |    \--- com.google.android.gms:play-services-iid-license:11.4.2
|    |    \--- com.google.android.gms:play-services-gcm-license:11.4.2
|    +--- com.android.support:appcompat-v7:26.1.0 (*)
|    +--- com.android.volley:volley:1.0.0
|    +--- io.skygear:volleyEx:0.0.1
|    |    +--- com.google.code.gson:gson:2.8.0
|    |    \--- com.android.volley:volley:1.0.0
|    +--- joda-time:joda-time:2.9.4
|    \--- org.java-websocket:Java-WebSocket:1.3.5
+--- com.google.firebase:firebase-core:11.4.2
|    \--- com.google.firebase:firebase-analytics:11.4.2
|         +--- com.google.android.gms:play-services-basement:11.4.2 (*)
|         +--- com.google.firebase:firebase-common:11.4.2
|         |    +--- com.google.android.gms:play-services-basement:11.4.2 (*)
|         |    +--- com.google.android.gms:play-services-tasks:11.4.2 (*)
|         |    \--- com.google.firebase:firebase-common-license:11.4.2
|         +--- com.google.firebase:firebase-analytics-impl:11.4.2
|         |    +--- com.google.android.gms:play-services-basement:11.4.2 (*)
|         |    +--- com.google.firebase:firebase-iid:11.4.2
|         |    |    +--- com.google.android.gms:play-services-basement:11.4.2 (*)
|         |    |    +--- com.google.firebase:firebase-common:11.4.2 (*)
|         |    |    \--- com.google.firebase:firebase-iid-license:11.4.2
|         |    +--- com.google.firebase:firebase-common:11.4.2 (*)
|         |    +--- com.google.android.gms:play-services-tasks:11.4.2 (*)
|         |    \--- com.google.firebase:firebase-analytics-impl-license:11.4.2
|         \--- com.google.firebase:firebase-analytics-license:11.4.2

I am wondering if implementing com.google.firebase:firebase-messaging will handle push notifications for the users, without requiring them to implement FCM related things on their own?