Reputation: 441
So, I can't afford a codeameone pro account, so I implemented native push notifications for Android with GCM. After some struggle I had it working.
Now GCM is deprecated and I want to migrate to FCM. However, I ran into some issues because codename one doesn't allow me to inject the right dependencies into the build.gradle file in order for the firebase app to initialize properly.
I described those here:
https://stackoverflow.com/questions/52278220/codenameone-firebaseapp-not-initializing
Also tried using some of the functionality for th pro account in order to add the right fcm dependencies to my app, meaning having my main applicatoin class implement the PushCallback interface, but I ran into other problems. For example, codenameone overrides my FirebaseMessagingService implementation, with a proprietary one, which throws an error when I'm sending a custom notification payload, via google fcm endpoint, which previously worked with my native implementation.
The error I get is this one:
09-12 14:50:19.581 14378 14397 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
09-12 14:50:19.581 14378 14397 E AndroidRuntime: at java.io.DataOutputStream.writeUTF(DataOutputStream.java:347)
09-12 14:50:19.581 14378 14397 E AndroidRuntime: at java.io.DataOutputStream.writeUTF(DataOutputStream.java:323)
09-12 14:50:19.581 14378 14397 E AndroidRuntime: at com.codename1.impl.android.AndroidImplementation.appendNotification(AndroidImplementation.java:470)
09-12 14:50:19.581 14378 14397 E AndroidRuntime: at com.codename1.impl.android.CN1FirebaseMessagingService.onMessageReceived(CN1FirebaseMessagingService.java:83)
09-12 14:50:19.581 14378 14397 E AndroidRuntime: at com.google.firebase.messaging.FirebaseMessagingService.zzc(Unknown Source)
09-12 14:50:19.581 14378 14397 E AndroidRuntime: at com.google.firebase.iid.zzc.run(Unknown Source)
09-12 14:50:19.581 14378 14397 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
09-12 14:50:19.581 14378 14397 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
09-12 14:50:19.581 14378 14397 E AndroidRuntime: at java.lang.Thread.run(Thread.java:761)
Apparently the CN1FirebaseMessagingService implementation expects a "body" parameter on the notification.
So right now I'm stuck, either not being able to add the right fcm dependencies to the build or not being able to implement my on FirebaseMessagingService.
My question is: Is there a way to add fcm support to my app without having a pro account and having to use codenameone servers to relay the push ?
I would prefer to use the fcm endpoing to send push notifications from my server and add custom notification handling on the device.
Thanks.
Upvotes: 3
Views: 230
Reputation: 441
Eventually I managed to implement FCM support natively by ading all the required dependencies via android.gradleDep build hint and initializing FirebaseApp manually, as described here: Can I initialize Firebase without using google-services.json?
Upvotes: 1