Я пытался использовать NotificationCompat с setFullScreenIntent и Wakelock, но не могу открыть действие для получения обратная связь.
Использованный код:
Код: Выделить всё
class AlarmReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val powerManager = context.getSystemService(Context.POWER_SERVICE) as PowerManager
val wakeLock = powerManager.newWakeLock(
PowerManager.SCREEN_BRIGHT_WAKE_LOCK or
PowerManager.FULL_WAKE_LOCK or
PowerManager.ACQUIRE_CAUSES_WAKEUP,
"app::feedback"
)
wakeLock.acquire(10000)
Handler(Looper.getMainLooper()).postDelayed({
showNotification(context)
}, 1000) // secondi = 1 secondo di ritardo
}
private fun showNotification(context: Context) {
val intent = Intent(context, FullScreenActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
val pendingIntent = PendingIntent.getActivity(
context,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
val vibrationPattern = longArrayOf(0, 500, 250, 500) // Vibra per 500ms, pausa di 250ms, vibra per 500ms
val notification = NotificationCompat.Builder(context, MainActivity.CHANNEL_ID)
.setSmallIcon(R.drawable.abc_vector_test)
.setContentTitle("Timer Scaduto")
.setContentText("Il tuo timer è scaduto!")
.setPriority(NotificationCompat.PRIORITY_MAX)
.setCategory(NotificationCompat.CATEGORY_ALARM)
.setContentIntent(pendingIntent)
.setFullScreenIntent(pendingIntent, true)
.setVibrate(vibrationPattern)
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setAutoCancel(false)
.build()
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(generateRandomNotificationId(), notification)
}
private fun generateRandomNotificationId(): Int {
return (System.currentTimeMillis() % Int.MAX_VALUE).toInt()
}
пока у меня такое поведение, т. е. при выключенном экране активируется и показывается уведомление в полноэкранном режиме, но его нельзя настроить.< /п>
Подробнее здесь: https://stackoverflow.com/questions/787 ... on-wear-os