by Anonymous » 12 Mar 2025, 11:02
Ich habe eine Erinnerungs -App erstellt und im Vergleich zur veröffentlichten Version die Benachrichtigungssendungsmethode aktualisiert. Die Benachrichtigungen sind jedoch nicht mehr veröffentlicht.
Code: Select all
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>
Diese Wakelock -Klasse < /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
}
}
Dies ist Alarmhelper -Klasse
https://pastebin.com/bermezeq
Dies ist eine notifizierende Klasse
https://pastebin.com/UUR8DUWV
Manifest
Ich habe festgestellt, dass der Benachrichtigungskanal in App -Info in Android -Einstellungen nicht erscheint
Ich habe eine Erinnerungs -App erstellt und im Vergleich zur veröffentlichten Version die Benachrichtigungssendungsmethode aktualisiert. Die Benachrichtigungen sind jedoch nicht mehr veröffentlicht.[code]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>
Diese Wakelock -Klasse < /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
}
}
[/code]
Dies ist Alarmhelper -Klasse https://pastebin.com/bermezeq
Dies ist eine notifizierende Klasse https://pastebin.com/UUR8DUWV
Manifest
[code]
[/code]
Ich habe festgestellt, dass der Benachrichtigungskanal in App -Info in Android -Einstellungen nicht erscheint