Created
June 4, 2020 00:11
-
-
Save DjangoLC/364401885a227b891dfd0844755f72b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyFirebaseMessagingService : FirebaseMessagingService() { | |
private val userPreferences: UserPreferences by inject() | |
override fun onMessageReceived(remoteMessage: RemoteMessage) { | |
// ... | |
// TODO(developer): Handle FCM messages here. | |
// Not getting messages here? See why this may be: https://goo.gl/39bRNJ | |
Timber.e("From: %s", remoteMessage.from) | |
// Check if message contains a data payload. | |
if (remoteMessage.data.isNotEmpty()) { | |
Timber.e("Message data payload: %s", remoteMessage.data) | |
Timber.e("Message body: %s", remoteMessage.notification!!.body) | |
} | |
// Check if message contains a notification payload. | |
if (remoteMessage.notification != null) { | |
Timber.e("Message Notification Body: %s", remoteMessage.notification!!.body) | |
} | |
// Also if you intend on generating your own notifications as a result of a received FCM | |
// message, here is where that should be initiated. See sendNotification method below. | |
} | |
/** | |
* Called if InstanceID token is updated. This may occur if the security of | |
* the previous token had been compromised. Note that this is called when the InstanceID token | |
* is initially generated so this is where you would retrieve the token. | |
*/ | |
override fun onNewToken(token: String) { | |
Log.e("TAGGGGG","Refreshed token: $token") | |
userPreferences.save(UserPreferences.USER_TOKEN, token) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment