fix #160, alarm on Android 10. Originally by coxtor

This commit is contained in:
tibbi 2020-02-14 19:00:04 +01:00
parent b4968e6863
commit b85333c984
4 changed files with 52 additions and 4 deletions

View File

@ -8,6 +8,7 @@
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission
android:name="android.permission.USE_FINGERPRINT"

View File

@ -1,5 +1,7 @@
package com.simplemobiletools.clock.activities
import android.annotation.SuppressLint
import android.app.NotificationManager
import android.content.Intent
import android.media.AudioManager
import android.media.MediaPlayer
@ -16,6 +18,7 @@ import com.simplemobiletools.clock.helpers.getPassedSeconds
import com.simplemobiletools.clock.models.Alarm
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.MINUTE_SECONDS
import com.simplemobiletools.commons.helpers.isOreoPlus
import kotlinx.android.synthetic.main.activity_reminder.*
class ReminderActivity : SimpleActivity() {
@ -73,6 +76,7 @@ class ReminderActivity : SimpleActivity() {
}
}
@SuppressLint("NewApi")
private fun setupAlarmButtons() {
reminder_stop.beGone()
reminder_draggable_background.startAnimation(AnimationUtils.loadAnimation(this, R.anim.pulsing_animation))
@ -120,12 +124,20 @@ class ReminderActivity : SimpleActivity() {
didVibrate = true
finishActivity()
}
if (isOreoPlus()) {
getSystemService(NotificationManager::class.java).cancelAll()
}
} else if (reminder_draggable.x <= minDragX + 50f) {
if (!didVibrate) {
reminder_draggable.performHapticFeedback()
didVibrate = true
snoozeAlarm()
}
if (isOreoPlus()) {
getSystemService(NotificationManager::class.java).cancelAll()
}
}
}
}

View File

@ -28,6 +28,7 @@ const val REMINDER_ACTIVITY_INTENT_ID = 9995
const val OPEN_ALARMS_TAB_INTENT_ID = 9996
const val UPDATE_WIDGET_INTENT_ID = 9997
const val OPEN_APP_INTENT_ID = 9998
const val ALARM_NOTIF_ID = 9998
const val TIMER_NOTIF_ID = 9999
const val OPEN_TAB = "open_tab"

View File

@ -1,14 +1,24 @@
package com.simplemobiletools.clock.receivers
import android.annotation.SuppressLint
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Handler
import androidx.core.app.NotificationCompat
import com.simplemobiletools.clock.R
import com.simplemobiletools.clock.activities.ReminderActivity
import com.simplemobiletools.clock.extensions.*
import com.simplemobiletools.clock.helpers.ALARM_ID
import com.simplemobiletools.clock.helpers.ALARM_NOTIF_ID
import com.simplemobiletools.commons.helpers.isOreoPlus
class AlarmReceiver : BroadcastReceiver() {
@SuppressLint("NewApi")
override fun onReceive(context: Context, intent: Intent) {
val id = intent.getIntExtra(ALARM_ID, -1)
val alarm = context.dbHelper.getAlarmWithId(id) ?: return
@ -19,10 +29,34 @@ class AlarmReceiver : BroadcastReceiver() {
context.hideNotification(id)
}, context.config.alarmMaxReminderSecs * 1000L)
} else {
Intent(context, ReminderActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra(ALARM_ID, id)
context.startActivity(this)
if (isOreoPlus()) {
val notificationManager = context.getSystemService(NotificationManager::class.java)
if (notificationManager.getNotificationChannel("Alarm") == null) {
val channel = NotificationChannel("Alarm", "Alarm", NotificationManager.IMPORTANCE_HIGH)
channel.setBypassDnd(true)
notificationManager.createNotificationChannel(channel)
}
val pendingIntent = PendingIntent.getActivity(context, 0, Intent(context, ReminderActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra(ALARM_ID, id)
}, PendingIntent.FLAG_UPDATE_CURRENT)
val builder = NotificationCompat.Builder(context, "Alarm")
.setSmallIcon(R.drawable.ic_alarm_vector)
.setContentTitle(context.getString(R.string.alarm))
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_ALARM)
.setFullScreenIntent(pendingIntent, true)
notificationManager.notify(ALARM_NOTIF_ID, builder.build())
} else {
Intent(context, ReminderActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra(ALARM_ID, id)
context.startActivity(this)
}
}
}
}