Это класс приемника: < /p>
Код: Выделить всё
class NewAlarmReceiver : BroadcastReceiver() {
@SuppressLint("ScheduleExactAlarm")
override fun onReceive(context: Context, intent: Intent) {
d(DEBUG_TAG, "Recurring alarm; requesting download service.")
WakeLocker.acquire(context)
WakeLocker.release()
val action = "" + intent.action
if (action.equals("SNOOZE_ACTION", ignoreCase = true)) {
val snoozeIntent = Intent(context, NewAlarmReceiver::class.java)
val snoozePendingIntent = PendingIntent.getBroadcast(context, 0, snoozeIntent,
PendingIntent.FLAG_IMMUTABLE)
val alarms = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
alarms.setExact(
AlarmManager.RTC_WAKEUP,
Calendar.getInstance(Locale.getDefault()).timeInMillis + 2 * 60000,
snoozePendingIntent
)
val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancel(99)
} else if (action == "android.intent.action.BOOT_COMPLETED") {
val alarmHelper = NewAlarmHelper(context)
alarmHelper.createAlarm()
} else {
val notificationHelper = NewNotificationHelper(context)
notificationHelper.createNotification()
}
}
companion object {
private const val DEBUG_TAG = "AlarmReceiver"
}
< /code>
Этот класс Wakelock < /p>
object WakeLocker {
private var wakeLock: PowerManager.WakeLock? = null
@SuppressLint("InvalidWakeLockTag")
fun acquire(ctx: Context) {
if (wakeLock != null) wakeLock!!.release()
val pm = ctx.getSystemService(Context.POWER_SERVICE) as PowerManager
wakeLock = pm.newWakeLock(
PowerManager.FULL_WAKE_LOCK or
PowerManager.ACQUIRE_CAUSES_WAKEUP or
PowerManager.ON_AFTER_RELEASE, ""
)
wakeLock!!.acquire(10*60*1000L /*10 minutes*/)
}
fun release() {
if (wakeLock != null) wakeLock!!.release()
wakeLock = null
}
}
Это уведомление. https://pastebin.com/qdxqdcvq
Наконец -то Manifest
Код: Выделить всё
Это экран. />
Подробнее здесь: https://stackoverflow.com/questions/795 ... on-anymore