android - FirebaseMessasingService 从我的服务器获取通知,但如果我使用 FirebaseConsole,则不会调用我的类
问题描述
这就是我在 AndroidManifest 中的内容:
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="io.smooch.core.service.SmoochService" />
<service android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
我正在使用版本:implementation 'com.google.firebase:firebase-messaging:17.0.0'
这就是我的 FirebaseMessagingService 的样子:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
public void onMessageReceived(final RemoteMessage message) {
Log.i("", "MyFirebaseMessagingService onMessageReceived");
final Map data = message.getData();
FcmService.triggerSmoochNotification(data, this);
final Map bundle = data;
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
Log.i("", "GLOBAL intances before GCM:" + Realm.getGlobalInstanceCount(PSApplicationClass.Config));
try {
String title = getString(R.string.alert_title_warning) + " " + getString(R.string.trips_remaining_free, user.getTrips_left());
String message = getString(R.string.alert_freemium_upgrade);
Notification.generateNotificationStandard(MyFirebaseMessagingService.this, title, message, null, null, false, false);
} catch (Exception e) {
Utils.appendLog("GCMIntentService onMessageReceived error: " + e.getMessage(), "E", Constants.PUSH_NOTIFICATIONS);
}
}
});
}
}
基本上我在这个函数的 onMessageReceived 处放了一个断点。
如果服务器向我的应用程序发送通知,该服务将收到通知,我可以根据需要进行处理。但。如果我使用 FirebaseConsole -> GROW -> Can Messaging -> 我创建一个新消息并发送它。我的应用会收到通知。但它会在不输入我的 onMessageReceived 方法的情况下“自动”创建。我怎么能强迫它这样做?这是我通过控制台发送的数据: https ://s3.amazonaws.com/uploads.hipchat.com/39260/829560/7Pp0KJIERZ8XVZZ/upload.png
我究竟做错了什么?
编辑:
就像我说的,我收到通知,但通知是自动创建的,而不是通过我的 FirebaseMessaging 服务。
我确实设法改变了这样的图标:
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/notification_icon" />
但是当我得到它时,我仍然需要运行其他代码,而不仅仅是显示它。我不知道怎么做
解决方案
推荐阅读
- r - 通过 WDI 加载 Wold Bank 数据的有效方法
- laravel - 如何使用 Laravel Query Builder 同时进行树连接?
- scala - 有没有办法让 GNU xgettext (或类似的东西)与 scala 文件一起工作?
- mysql - 通过比较 2 个表中的 2 个列来获取 MySQL 中的重复记录
- reactjs - 浏览器缓存存储问题
- c# - 处理相同依赖项的不同版本
- javascript - 递归地将对象字段从蛇案例转换为骆驼案例
- apache-superset - 如何在受保护的服务器中安装 apache 超集(无互联网)
- c# - 如何拆分 HtmlNode
,然后从每个拆分字符串中提取 InnerText? - python - 从 python 库添加自定义 Ansible 模块?