From 3466799c94227c5ebba9fb201621e745058867ee Mon Sep 17 00:00:00 2001 From: cloudroam <cloudroam> Date: 星期二, 15 四月 2025 13:18:34 +0800 Subject: [PATCH] add: 消息提醒时间设定;会员到期时间调整; --- app/src/main/java/com/example/firstapp/MainActivity.kt | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-) diff --git a/app/src/main/java/com/example/firstapp/MainActivity.kt b/app/src/main/java/com/example/firstapp/MainActivity.kt index 13ae51e..9c533a8 100644 --- a/app/src/main/java/com/example/firstapp/MainActivity.kt +++ b/app/src/main/java/com/example/firstapp/MainActivity.kt @@ -75,6 +75,9 @@ // 只保留底部导航的设置 navView.setupWithNavController(navController) + // 重置提醒计划并检查是否有错过的提醒 + resetReminders() + // 检查权限 if (ContextCompat.checkSelfPermission( this, Manifest.permission.RECEIVE_SMS @@ -323,4 +326,25 @@ Toast.makeText(this, "同步短信失败:${e.message}", Toast.LENGTH_SHORT).show() } } + + // 重置提醒计划 + private fun resetReminders() { + try { + // 取消所有现有的提醒任务 + androidx.work.WorkManager.getInstance(this).cancelAllWorkByTag("reminder_worker") + + // 清除旧的提醒偏好设置 + getSharedPreferences("reminder_prefs", Context.MODE_PRIVATE).edit().clear().apply() + + // 重新设置提醒任务 + (application as App).setupReminderWorker() + + // 检查是否有错过的提醒 + com.example.firstapp.service.ReminderWorker.checkMissedReminders(this) + + android.util.Log.d("MainActivity", "已重置提醒计划") + } catch (e: Exception) { + android.util.Log.e("MainActivity", "重置提醒计划失败: ${e.message}") + } + } } \ No newline at end of file -- Gitblit v1.9.3