У меня есть настройка одного действия с помощью Jetpack Compose. BroadcastReceiver просто создает уведомление и намерение открыть основное действие (которое позже перейдет на экран тревоги) следующим образом:
Код: Выделить всё
val notificationManager = context?.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(mChannel)
val alarmIntent = Intent(context, MainActivity::class.java)
alarmIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
val options = ActivityOptions.makeBasic().setPendingIntentCreatorBackgroundActivityStartMode(ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED)
// Create a pending intent with the above intent
val fullScreenPendingIntent = PendingIntent.getActivity(
context, 0, alarmIntent, PendingIntent.FLAG_IMMUTABLE, options.toBundle()
)
val builder = NotificationCompat.Builder(context!!, "alarm_channel")
.setSmallIcon(android.R.drawable.ic_lock_idle_alarm)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setCategory(NotificationCompat.CATEGORY_ALARM)
.setOngoing(true)
.setFullScreenIntent(fullScreenPendingIntent, true)
// Build the notification
// Show the notification
with(NotificationManagerCompat.from(context)) {
notify(Random().nextInt(32), builder.build())
}
Код: Выделить всё
setShowWhenLocked(true)Код: Выделить всё
setTurnScreenOn(true)Код: Выделить всё
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)Код: Выделить всё
Permissions in manifest: USE_EXACT_ALARM, POST_NOTIFICATIONS, USE_FULL_SCREEN_INTENTКод: Выделить всё
MainActivity manifest: android:showWhenLocked="true", android:turnScreenOn="true", android:showForAllUsers="true, android:launchMode="singleInstance"Код: Выделить всё
pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK or PowerManager.FULL_WAKE_LOCK, TAG).acquire(TIMEOUT)- Разрешить фоновую активность в настройках.
- Нет режима энергосбережения.
- Включить экран. пока звенит будильник
Я предполагаю, что это как-то связано с тем, что экран/процессор не активируется, но я перепробовал все, что смог найти, но безуспешно.
Подробнее здесь: https://stackoverflow.com/questions/788 ... android-14
Мобильная версия