Я пытаюсь создать полноэкранное уведомление о намерениях, но я застрял. Например, когда приходит вызов, вызововый пользовательский интерфейс показывает, даже когда вызовое приложение не открыто. Но это только показывает уведомления, но не идет полный экран. < /P>
class MyFirebaseMessagingService : FirebaseMessagingService() {
override fun onNewToken(token: String) {
Log.d("FCM", "New token: $token")
}
override fun onMessageReceived(remoteMessage: RemoteMessage) {
Log.d("FCM", "Message received")
navigate()
}
private fun navigate() {
val activityIntent = Intent(this, ReceiveMessage::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
}
val fullScreenPendingIntent = PendingIntent.getActivity(this, 0,
activityIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE)
val notification = NotificationCompat.Builder(this, getString(R.string.CHANNEL_ID))
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle("Incoming Call")
.setContentText("Someone is calling you...")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_CALL)
.setFullScreenIntent(fullScreenPendingIntent, true)
.setAutoCancel(false)
.setOngoing(true)
.build()
// Start a foreground service to show notification with full screen intent
val serviceIntent = Intent(this, CallForegroundService::class.java).apply {
putExtra("notification", notification)
}
ContextCompat.startForegroundService(this, serviceIntent)
}
}
< /code>
class MyApplication: Application() {
override fun onCreate() {
super.onCreate()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Create the NotificationChannel.
val name = getString(R.string.channel_name)
val descriptionText = getString(R.string.channel_description)
val channelId = getString(R.string.CHANNEL_ID)
val importance = NotificationManager.IMPORTANCE_HIGH
val mChannel = NotificationChannel(channelId, name, importance)
mChannel.description = descriptionText
mChannel.lockscreenVisibility = NotificationCompat.VISIBILITY_PUBLIC
// Register the channel with the system. You can't change the importance
// or other notification behaviors after this.
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(mChannel)
}
}
}
< /code>
class CallForegroundService : Service() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val notification = intent?.getParcelableExtra("notification")
if (notification != null) {
Log.d(TAG, "Starting foreground with notification")
startForeground(1, notification)
} else {
Log.e(TAG, "Notification is null")
}
// Stop service after 30 seconds if not answered
Handler(Looper.getMainLooper()).postDelayed({ stopSelf() }, 30000)
return START_NOT_STICKY
}
override fun onBind(intent: Intent?): IBinder? = null
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... -messaging
Полное уведомление ⇐ Android
Форум для тех, кто программирует под Android
1746597569
Anonymous
Я пытаюсь создать полноэкранное уведомление о намерениях, но я застрял. Например, когда приходит вызов, вызововый пользовательский интерфейс показывает, даже когда вызовое приложение не открыто. Но это только показывает уведомления, но не идет полный экран. < /P>
class MyFirebaseMessagingService : FirebaseMessagingService() {
override fun onNewToken(token: String) {
Log.d("FCM", "New token: $token")
}
override fun onMessageReceived(remoteMessage: RemoteMessage) {
Log.d("FCM", "Message received")
navigate()
}
private fun navigate() {
val activityIntent = Intent(this, ReceiveMessage::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
}
val fullScreenPendingIntent = PendingIntent.getActivity(this, 0,
activityIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE)
val notification = NotificationCompat.Builder(this, getString(R.string.CHANNEL_ID))
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle("Incoming Call")
.setContentText("Someone is calling you...")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_CALL)
.setFullScreenIntent(fullScreenPendingIntent, true)
.setAutoCancel(false)
.setOngoing(true)
.build()
// Start a foreground service to show notification with full screen intent
val serviceIntent = Intent(this, CallForegroundService::class.java).apply {
putExtra("notification", notification)
}
ContextCompat.startForegroundService(this, serviceIntent)
}
}
< /code>
class MyApplication: Application() {
override fun onCreate() {
super.onCreate()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Create the NotificationChannel.
val name = getString(R.string.channel_name)
val descriptionText = getString(R.string.channel_description)
val channelId = getString(R.string.CHANNEL_ID)
val importance = NotificationManager.IMPORTANCE_HIGH
val mChannel = NotificationChannel(channelId, name, importance)
mChannel.description = descriptionText
mChannel.lockscreenVisibility = NotificationCompat.VISIBILITY_PUBLIC
// Register the channel with the system. You can't change the importance
// or other notification behaviors after this.
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(mChannel)
}
}
}
< /code>
class CallForegroundService : Service() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val notification = intent?.getParcelableExtra("notification")
if (notification != null) {
Log.d(TAG, "Starting foreground with notification")
startForeground(1, notification)
} else {
Log.e(TAG, "Notification is null")
}
// Stop service after 30 seconds if not answered
Handler(Looper.getMainLooper()).postDelayed({ stopSelf() }, 30000)
return START_NOT_STICKY
}
override fun onBind(intent: Intent?): IBinder? = null
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79609698/full-screen-notification-not-working-on-android-with-firebase-cloud-messaging[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия