This is my Java service class FCM
public class MyFirebaseMessagingService extends FirebaseMessagingService { private static final String TAG = "FCM Data Tag" ;
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
// TODO(developer): Handle FCM messages here.
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
String data= remoteMessage.getNotification().getBody();
String details[] = (data.split("\n"));
String username,location,serviceType,date,time,area;
username=details[0];
location=details[1];
serviceType=details[2];
date=details[3];
time=details[4];
area=details[5];
Intent i=new Intent(getApplicationContext(),FragmentHome.class);
i.putExtra("user",username);
i.putExtra("loc",location);
i.putExtra("type",serviceType);
i.putExtra("Date",date);
i.putExtra("Time",time);
i.putExtra("Area",area);
}
And i dont know how to receieve the data in kotlin class.
In the onCreate method of kotlin activity you need to get these variable as below -
val user:String = intent.getStringExtra("user")
val loc:String = intent.getStringExtra("loc")
val type:String = intent.getStringExtra("type")
val date:String = intent.getStringExtra("Date")
val time:String = intent.getStringExtra("Time")
val area:String = intent.getStringExtra("Area")