cloudroam
2025-04-15 3466799c94227c5ebba9fb201621e745058867ee
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}")
        }
    }
}