【发布时间】:2016-10-09 05:34:12
【问题描述】:
按照 Firebase dev docs 中的说明,我实现了一个扩展 FirebaseMessagingService 并覆盖 onMessageReceived 回调的服务。我在 onMessageReceived 方法的第一行中放置了一条日志消息。
应用在后台运行 我在 logcat 中看不到日志,但我看到系统尝试中发布了一条通知。
前台应用 我在系统托盘中既没有看到日志也没有看到通知
知道发生了什么吗?
清单
<service
android:name=".fcm.MovieMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
服务类
public class MovieMessagingService extends FirebaseMessagingService {
private static final String LOG_TAG = MovieMessagingService.class.getSimpleName();
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(LOG_TAG, "From: " + remoteMessage.getFrom());
}
/**
* Create and show a simple notification containing the received FCM message.
*
* @param messageBody FCM message body received.
*/
private void sendNotification(String messageBody) {
Log.d(LOG_TAG, "Presenting Notification with message body: " + messageBody);
//more code
}
}
【问题讨论】:
-
将您的服务类代码和清单代码添加到问题中
-
是服务的正确路径(包名)
-
是的,否则应用程序甚至无法编译。如您所见,我在清单中使用相对路径-“.fcm.MovieMessagingService”
-
你如何将消息发送到设备?
-
来自 Firebase 控制台。 console.firebase.google.com -> 通知->新消息
标签: android firebase firebase-cloud-messaging firebase-notifications