Skip to content

Instantly share code, notes, and snippets.

@mariusz-blaszczak
Created August 28, 2018 10:30
Show Gist options
  • Save mariusz-blaszczak/75283dfff0e5ba20de2da37027168878 to your computer and use it in GitHub Desktop.
Save mariusz-blaszczak/75283dfff0e5ba20de2da37027168878 to your computer and use it in GitHub Desktop.
class AppMessagingService : FirebaseMessagingService() {
override fun onNewToken(token: String?) {
val registrationId = token ?: return
val userId = UUIDProvider.provide(this) // described later
// request push registration
}
override fun onMessageReceived(remoteMessage: RemoteMessage) {
super.onMessageReceived(remoteMessage)
Log.i(TAG, "Message received.")
AppCache.lockState = remoteMessage.getLockState()
LockWidgetProvider.showLockState(this)
}
private fun RemoteMessage.getLockState(): LockState? {
val json = data.get("state") ?: return null
return LockState.fromJson(json)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment