当我尝试在firebase中使用自定义数据发送通知时,我没有在后台收到通知
我的firebase服务代码是:
在on消息接收方法
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.e("fcm", "received notification");
if (remoteMessage == null)
return;
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.e(TAG, "Data Payload: " + remoteMessage.getData().toString());
try {
int badge = Integer.parseInt(remoteMessage.getData().get("badge"));
String message = remoteMessage.getData().get("message");
String timestamp = remoteMessage.getData().get("timestamp");
handleDataMessage(badge,message,timestamp);
badgeStore = Integer.parseInt(remoteMessage.getData().get("badge"));
} catch (Exception e) {
Log.e(TAG, "Exception: " + e.getMessage());
}
}
}
请在Menifest文件中注册您的firebase服务
<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
在应用程序标签中添加这些行以设置自定义默认图标和自定义颜色:
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_stat_ic_notification" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent" />