Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package m.kampukter.myfirebaseapplication
- import android.util.Log
- import androidx.core.app.NotificationCompat
- import androidx.core.app.NotificationManagerCompat
- import com.google.firebase.messaging.FirebaseMessagingService
- import com.google.firebase.messaging.RemoteMessage
- class MyFCMService : FirebaseMessagingService() {
- override fun onNewToken(token: String) {
- Log.d("blablabla", "Refreshed token: $token")
- // получили токен для того чтоб могли сюда присылать адресные сообщения
- }
- override fun onMessageReceived(remoteMessage: RemoteMessage) {
- Log.d("blablabla", "From: ${remoteMessage.from}")
- remoteMessage.notification?.let {
- Log.d("blablabla", "Message Notification Body: ${it.body}")
- val builder = NotificationCompat.Builder(
- this,
- getString(R.string.default_notification_channel_id)
- )
- .setContentTitle(it.title)
- .setContentText(it.body)
- .setSmallIcon(R.drawable.ic_call)
- .setPriority(NotificationCompat.PRIORITY_DEFAULT)
- with(NotificationManagerCompat.from(this)) {
- // notificationId is a unique int for each notification that you must define
- notify(0, builder.build())
- }
- }
- remoteMessage.data.let {
- Log.d("blablabla", "Message Data Body: ${it}")
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement