Reputation: 9564
I am using Firebase to push notification from server to a specific android device. I want to get time when notification is received (device's local time not server time). How can I get that?
Because I have to show a timer with respect to that time so that is why I need that exact time when notification received on that device.
Upvotes: 2
Views: 4494
Reputation: 6884
You can use this firebase function in the onMessageReceived()
method:
Long time = remoteMessage.getSentTime();
Hope this helps :)
Upvotes: 5
Reputation: 362
String currentDateTimeString = DateFormat.getDateInstance().format(new Date());
Write this line in your service class which extends FirebaseMessagingService . The function is looked like
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
String currentDateTimeString = DateFormat.getDateInstance().format(new Date());
Log.d("time",currentDateTimeString);
createNotification(remoteMessage.getNotification().getBody());
}
Upvotes: 1
Reputation: 2872
I think an effective way would be use the Calendar class in your onMessageReceived() somewhat like this :
Calendar.getInstance().getTimeInMillis();
Upvotes: 4