|
@@ -0,0 +1,43 @@
|
|
|
|
+package com.swago.app
|
|
|
|
+
|
|
|
|
+import android.app.NotificationManager
|
|
|
|
+import android.app.PendingIntent
|
|
|
|
+import android.content.Context
|
|
|
|
+import android.content.Intent
|
|
|
|
+import androidx.core.app.NotificationCompat
|
|
|
|
+import com.google.firebase.messaging.FirebaseMessagingService
|
|
|
|
+import com.google.firebase.messaging.RemoteMessage
|
|
|
|
+import com.swago.baseswago.util.LogUtil
|
|
|
|
+import com.swago.home.HomeActivity
|
|
|
|
+
|
|
|
|
+class MyFirebaseMessagingService: FirebaseMessagingService() {
|
|
|
|
+
|
|
|
|
+ override fun onMessageReceived(message: RemoteMessage) {
|
|
|
|
+ super.onMessageReceived(message)
|
|
|
|
+ LogUtil.d("MyFirebaseMessagingService","onMessageReceived")
|
|
|
|
+ message.notification?.body?.let {
|
|
|
|
+ sendNotification(it)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onNewToken(token: String) {
|
|
|
|
+ super.onNewToken(token)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun sendNotification(messageBody: String) {
|
|
|
|
+ val intent = Intent(this, HomeActivity::class.java)
|
|
|
|
+ intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
|
|
|
|
+ val pendIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_IMMUTABLE)
|
|
|
|
+ val channelId = "default_channel_id"
|
|
|
|
+ val notificationBuilder = NotificationCompat.Builder(this, channelId)
|
|
|
|
+ .setSmallIcon(R.mipmap.ic_launcher_foreground)
|
|
|
|
+ .setContentTitle("FCM Message")
|
|
|
|
+ .setContentText(messageBody)
|
|
|
|
+ .setAutoCancel(true)
|
|
|
|
+ .setContentIntent(pendIntent)
|
|
|
|
+
|
|
|
|
+ val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
|
|
+ notificationManager.notify(0, notificationBuilder.build())
|
|
|
|
+ }
|
|
|
|
+}
|