【发布时间】:2017-09-22 07:18:42
【问题描述】:
我有一个集成了 firebase 的 android 应用。
- 我一开始就成功收到了 Firebase 注册 ID。
但是当我将消息从 firebase 控制台发送到我的应用程序时,我没有在手机中收到它
这是我的应用程序 gradle
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.google.firebase:firebase-auth:11.0.4'
compile 'com.android.support:design:25.3.1'
compile 'com.google.firebase:firebase-core:10.2.1'
compile 'com.google.firebase:firebase-messaging:10.2.1'
构建等级
classpath 'com.google.gms:google-services:3.0.0'
我有一个单独的类 MyFirebaseMessagingService,它扩展了 FirebaseMessagingService
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.e(TAG, "From: " + remoteMessage.getFrom());
Log.e("tagg", "From: " + remoteMessage.getFrom());
if (remoteMessage == null)
return;
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.e(TAG, "Notification Body: " + remoteMessage.getNotification().getBody());
handleNotification(remoteMessage.getNotification().getBody());
}
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.e(TAG, "Data Payload: " + remoteMessage.getData().toString());
try {
JSONObject json = new JSONObject(remoteMessage.getData().toString());
handleDataMessage(json);
} catch (Exception e) {
Log.e(TAG, "Exception: " + e.getMessage());
}
}
我在这个类中没有得到任何日志。
怎么可能发生错误,我已经成功收到了 reg id ,那么可能是什么错误
【问题讨论】:
-
您是否尝试使用来自 firebase 的令牌 (onTokenRefresh) 发送消息?
-
当您尝试发送通知时,您的应用是否处于前台?尝试在应用处于后台时发送通知
-
请点击此链接firebase.google.com/docs/cloud-messaging/android/client 将firebase消息完整集成到android中。
-
看我的回答可能是因为错过了。
标签: android firebase firebase-cloud-messaging firebase-notifications