| | |
| | | // 只保留底部导航的设置 |
| | | navView.setupWithNavController(navController) |
| | | |
| | | // 重置提醒计划并检查是否有错过的提醒 |
| | | resetReminders() |
| | | |
| | | // 检查权限 |
| | | if (ContextCompat.checkSelfPermission( |
| | | this, Manifest.permission.RECEIVE_SMS |
| | |
| | | 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}") |
| | | } |
| | | } |
| | | } |