Advertisement
AnatolyZadvernyak

Untitled

Apr 15th, 2020
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. package m.kampukter.myfirebaseapplication
  2.  
  3. import android.util.Log
  4. import androidx.core.app.NotificationCompat
  5. import androidx.core.app.NotificationManagerCompat
  6. import com.google.firebase.messaging.FirebaseMessagingService
  7. import com.google.firebase.messaging.RemoteMessage
  8.  
  9. class MyFCMService : FirebaseMessagingService() {
  10.  
  11.  
  12. override fun onNewToken(token: String) {
  13. Log.d("blablabla", "Refreshed token: $token")
  14. // получили токен для того чтоб могли сюда присылать адресные сообщения
  15. }
  16.  
  17. override fun onMessageReceived(remoteMessage: RemoteMessage) {
  18. Log.d("blablabla", "From: ${remoteMessage.from}")
  19. remoteMessage.notification?.let {
  20. Log.d("blablabla", "Message Notification Body: ${it.body}")
  21. val builder = NotificationCompat.Builder(
  22. this,
  23. getString(R.string.default_notification_channel_id)
  24. )
  25. .setContentTitle(it.title)
  26. .setContentText(it.body)
  27. .setSmallIcon(R.drawable.ic_call)
  28. .setPriority(NotificationCompat.PRIORITY_DEFAULT)
  29.  
  30. with(NotificationManagerCompat.from(this)) {
  31. // notificationId is a unique int for each notification that you must define
  32. notify(0, builder.build())
  33. }
  34. }
  35. remoteMessage.data.let {
  36. Log.d("blablabla", "Message Data Body: ${it}")
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement