【发布时间】:2016-12-17 18:04:45
【问题描述】:
我正在使用 Firebase 云消息传递 API 创建应用程序...我能够从服务器向我的客户端应用程序发送通知和数据。 但问题是当应用程序打开时,通知没有在数据出现时触发(我的意思是我记录了它)这不是问题。但是当应用程序关闭时,会收到通知,当我单击通知时,活动已打开,而我看不到日志数据。我需要将数据更新到 TextView..
我的 MyFirebaseMessagingService :
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO: Handle FCM messages here.
// If the application is in the foreground handle both data and notification messages here.
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated.
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
Log.e("FROM", "From: " + remoteMessage.getFrom());
String data = remoteMessage.getData().get("message");
Log.e("KOIII", "Notification Message Body: " + remoteMessage.getNotification().getBody());
// showNotificationS(remoteMessage.getNotification().getBody(),2);
if(data.equals("true")){
Log.e("DATA", "SUCCESS");
// Fragment1.getInstace().updateTheTextView(data, data, data);
}
}
我的清单:
<activity
android:name=".SplashScreen"
android:label="@string/app_name"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".myHome"
android:label="@string/app_name">
</activity>
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service android:name=".FirebaseIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
【问题讨论】:
标签: android firebase-cloud-messaging