Настройка Android приложения
Настройка приложения для получения и отображения push-уведомлений
<service
android:name=".IDigitalFcmService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>Пример реализации FirebaseMessagingService:
class IDigitalFcmService : FirebaseMessagingService() {
override fun onNewToken(token: String) {
sendTokenToBackend(token)
}
override fun onMessageReceived(remoteMessage: RemoteMessage) {
if (remoteMessage.data.containsKey("messageId")) {
showNotification(remoteMessage.data["text"] as String)
// For long-running tasks (10 seconds or more) use WorkManager.
sendReceivedStateCallback(remoteMessage.data["messageId"] as String)
}
}
private fun showNotification(text: String) {
val intent = Intent(this, ScrollingActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
val pendingIntentFlags = if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
} else {
PendingIntent.FLAG_UPDATE_CURRENT
}
val pendingIntent = PendingIntent.getActivity(this, 0, intent, pendingIntentFlags)
val notificationBuilder = NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("Заголовок")
.setContentText(text)
.setSmallIcon(R.drawable.ic_notification_24)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_HIGH)
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel(notificationManager)
}
notificationManager.notify(Random.nextInt(), notificationBuilder.build())
}
@RequiresApi(Build.VERSION_CODES.O)
private fun createNotificationChannel(notificationManager: NotificationManager) {
val notificationChannel = NotificationChannel(
CHANNEL_ID,
"NotificationChannel",
NotificationManager.IMPORTANCE_HIGH
).apply {
description = "NotificationChannelDescription"
}
notificationManager.createNotificationChannel(notificationChannel)
}
companion object {
private const val CHANNEL_ID = "default_channel"
}
}Отслеживание статусов доставки
Отправка уведомлений
Как создать роль с разрешением на отправку сообщений в Firebase Cloud Messaging?






Как создать сервисный аккаунт и ключ?






Как передать созданный JSON ключ в i-Digital?
Последнее обновление