mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2025-04-03 13:21:01 +02:00
make sure the alarm uses the Alarm stream
This commit is contained in:
parent
7974381e76
commit
1d45ae9b48
@ -7,6 +7,8 @@ import android.app.PendingIntent
|
|||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.media.AudioAttributes
|
||||||
|
import android.net.Uri
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import com.simplemobiletools.clock.R
|
import com.simplemobiletools.clock.R
|
||||||
@ -30,11 +32,18 @@ class AlarmReceiver : BroadcastReceiver() {
|
|||||||
}, context.config.alarmMaxReminderSecs * 1000L)
|
}, context.config.alarmMaxReminderSecs * 1000L)
|
||||||
} else {
|
} else {
|
||||||
if (isOreoPlus()) {
|
if (isOreoPlus()) {
|
||||||
|
val audioAttributes = AudioAttributes.Builder()
|
||||||
|
.setUsage(AudioAttributes.USAGE_ALARM)
|
||||||
|
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
||||||
|
.build()
|
||||||
|
|
||||||
val notificationManager = context.getSystemService(NotificationManager::class.java)
|
val notificationManager = context.getSystemService(NotificationManager::class.java)
|
||||||
if (notificationManager.getNotificationChannel("Alarm") == null) {
|
if (notificationManager.getNotificationChannel("Alarm") == null) {
|
||||||
val channel = NotificationChannel("Alarm", "Alarm", NotificationManager.IMPORTANCE_HIGH)
|
NotificationChannel("Alarm", "Alarm", NotificationManager.IMPORTANCE_HIGH).apply {
|
||||||
channel.setBypassDnd(true)
|
setBypassDnd(true)
|
||||||
notificationManager.createNotificationChannel(channel)
|
setSound(Uri.parse(alarm.soundUri), audioAttributes)
|
||||||
|
notificationManager.createNotificationChannel(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val pendingIntent = PendingIntent.getActivity(context, 0, Intent(context, ReminderActivity::class.java).apply {
|
val pendingIntent = PendingIntent.getActivity(context, 0, Intent(context, ReminderActivity::class.java).apply {
|
||||||
@ -43,12 +52,12 @@ class AlarmReceiver : BroadcastReceiver() {
|
|||||||
}, PendingIntent.FLAG_UPDATE_CURRENT)
|
}, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||||
|
|
||||||
val builder = NotificationCompat.Builder(context, "Alarm")
|
val builder = NotificationCompat.Builder(context, "Alarm")
|
||||||
.setSmallIcon(R.drawable.ic_alarm_vector)
|
.setSmallIcon(R.drawable.ic_alarm_vector)
|
||||||
.setContentTitle(context.getString(R.string.alarm))
|
.setContentTitle(context.getString(R.string.alarm))
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||||
.setCategory(NotificationCompat.CATEGORY_ALARM)
|
.setCategory(NotificationCompat.CATEGORY_ALARM)
|
||||||
.setFullScreenIntent(pendingIntent, true)
|
.setFullScreenIntent(pendingIntent, true)
|
||||||
|
|
||||||
notificationManager.notify(ALARM_NOTIF_ID, builder.build())
|
notificationManager.notify(ALARM_NOTIF_ID, builder.build())
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user