Я пытаюсь реализовать то же поведение, что и приложение будильника в ОС Wear.
Я пытался использовать 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()
}
}
пока у меня такое поведение, т. е. при выключенном экране активируется и показывается уведомление в полноэкранном режиме, но его нельзя настроить.< /п>
Я пытаюсь реализовать то же поведение, что и приложение будильника в ОС Wear. Я пытался использовать NotificationCompat с setFullScreenIntent и Wakelock, но не могу открыть действие для получения обратная связь. Использованный код: [code]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() } [/code] } пока у меня такое поведение, т. е. при выключенном экране активируется и показывается уведомление в полноэкранном режиме, но его нельзя настроить.< /п>
Из приложения Wear я пытаюсь постоянно проверять, подключено ли устройство Wear к карманному устройству. Мы можем сделать это через Wearable.getNodeClient(context).connectedNodes. Есть ли способ добавить прослушиватель к этим данным? Кроме того,...
Мне нужно подключить эмулятор AVD Wear к смартфону. Когда я искал здесь документацию по этому поводу, там говорилось, что нужно перейти к настройкам, затем к настройкам устройства, а затем нажать «Эмулятор».
Я не понимаю, о каких настройках и...
Мне нужно подключить эмулятор AVD Wear к смартфону. Когда я искал здесь документацию по этому поводу, там говорилось, что нужно перейти к настройкам, затем к настройкам устройства, а затем нажать «Эмулятор».
Я не понимаю, о каких настройках и...
Я могу заставить Ladybug создать только MainActivity.kt, а не MainActivity.java. Приложение предназначено для Wear OS, а не для телефона и планшета. Как создать Java-приложение для носимого устройства в Android Studio Ladybug?
Для проекта я реализовал нечто похожее на счетчик шагов на умных часах Android . Теперь цель состоит в том, чтобы автоматически отображать какое-либо праздничное действие (окно, всплывающее окно...), если достигнуто указанное количество. Действие...