CodenameOne-Android推送通知支持,无需专业帐户 [英] CodenameOne - Android push notifications support, without a pro account

查看:54
本文介绍了CodenameOne-Android推送通知支持,无需专业帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我买不起Codeameone专业版帐户,因此我通过GCM为Android实施了本机推送通知。经过一番挣扎之后,我终于开始使用它了。

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.

现在不建议使用GCM,我想迁移到FCM。但是,我遇到了一些问题,因为代号 1不允许我将正确的依赖项注入到build.gradle文件中,以便Firebase应用正确初始化。

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

也尝试将某些功能用于为了向我的应用程序添加正确的fcm依赖关系,请使用专业帐户,这意味着让我的主要applicatoin类实现PushCallback接口,但是我遇到了其他问题。例如,codenameone使用专有的重写了FirebaseMessagingService的实现,当我通过google fcm端点发送自定义通知有效负载时,它会引发错误,该方法以前与本机实现一起使用。

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.

我得到的错误是这个:

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)

很显然,CN1FirebaseMessagingService实现在通知上需要一个 body参数。

Apparently the CN1FirebaseMessagingService implementation expects a "body" parameter on the notification.

因此,我现在陷入困境,要么无法向构建中添加正确的fcm依赖项,要么无法在FirebaseMessagingService上实现我的功能。

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.

我的问题是:有没有一种方法可以为我的应用添加fcm支持,而无需专业帐户,而不必使用codenameone服务器来中继推送?

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 ?

我希望使用fcm endpoing从服务器发送推送通知并在设备上添加自定义通知处理。

I would prefer to use the fcm endpoing to send push notifications from my server and add custom notification handling on the device.

谢谢。

推荐答案

最终,我设法通过android.gradleDep构建提示添加所有必需的依赖项并手动初始化FirebaseApp,从而实现了本地的FCM支持。如下所述:我是否可以在不使用google-services的情况下初始化Firebase。 json?

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?

这篇关于CodenameOne-Android推送通知支持,无需专业帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆