我正在使用Firebase云消息传递API创建应用程序...我能够将通知和数据从服务器发送到我的客户端应用程序。 但问题是当应用程序打开时,数据出现时通知不会触发(我的意思是我登录了它)这不是问题。但是,当应用程序关闭时,会收到通知,而我单击通知时,活动已打开,而我无法查看日志数据。我需要将数据更新到一个TextView ..Firebase通知和数据
我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>
是啊,我能做到这一点..但我需要的是..如果应用程序是在后台和通知被触发..但没有日志在我的logcat中看到,因为我打印的数据..我希望你得到的情况.. –
@KarthikCP请参阅这里http://stackoverflow.com/questions/38867199/how-get-message-body -fhen-fcm-notification-message-is-tap/ –
是的..我知道了..数据和通知,如果两者都使用这个问题存在,我希望..如果只使用数据,那么消息将被接收所有时间和可以创建通知.. http://stackoverflow.com/ a/37876727/3910281 –