I am Creating an App using Firebase cloud messaging API... I am able to send notification and data to my client application from the server.
But the problem is When the application is open the notification is not firing while the data appears (I Mean I logged it) It is not an issue. But when the application is closed, the notification is received, while I clicked on notification the activity is opened while I am not able to see the log data. I need to Update the data to a TextView..
My 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);
}
}
My manifest:
<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>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…