From 1a281d8354622a3606360f9f9a7fe4bb7d6a2c3a Mon Sep 17 00:00:00 2001
From: cloudroam <cloudroam>
Date: 星期日, 27 四月 2025 13:22:26 +0800
Subject: [PATCH] fix 短信
---
app/src/main/java/com/example/firstapp/App.kt | 30 +++++++++++-------------------
1 files changed, 11 insertions(+), 19 deletions(-)
diff --git a/app/src/main/java/com/example/firstapp/App.kt b/app/src/main/java/com/example/firstapp/App.kt
index 83a1eae..d672f03 100644
--- a/app/src/main/java/com/example/firstapp/App.kt
+++ b/app/src/main/java/com/example/firstapp/App.kt
@@ -16,6 +16,7 @@
import com.example.firstapp.database.repository.CodeRepository
import com.example.firstapp.database.repository.KeywordRepository
import com.example.firstapp.database.repository.MsgRepository
+import com.example.firstapp.database.repository.ReminderRepository
import com.example.firstapp.database.service.RetrofitClient
import com.example.firstapp.receiver.CactusReceiver
import com.example.firstapp.service.ReminderWorker
@@ -37,6 +38,7 @@
import java.io.IOException
import java.text.SimpleDateFormat
import java.util.*
+import java.util.concurrent.TimeUnit
@Suppress("DEPRECATION")
class App : Application(), CactusCallback, Configuration.Provider {
@@ -46,6 +48,7 @@
val msgRepository by lazy { MsgRepository(database.msgDao()) }
val codeRepository by lazy { CodeRepository(database.codeDao()) }
val keywordRepository by lazy { KeywordRepository(RetrofitClient.apiService,database.keywordDao()) }
+ val reminderRepository by lazy { ReminderRepository(this) }
companion object {
const val TAG: String = "SmsForwarder"
@@ -130,6 +133,8 @@
context = applicationContext
initLibs()
PreferencesManager.init(this)
+ // 初始化RetrofitClient
+ RetrofitClient.init(this)
try {
if (SettingUtils.enablePureClientMode) return
@@ -452,28 +457,15 @@
* 设置定时提醒Worker
* 配置为每天运行一次检查是否有新的提醒内容
*/
- private fun setupReminderWorker() {
+ fun setupReminderWorker() {
Log.d(TAG, "设置定时提醒Worker")
- val constraints = Constraints.Builder()
- .setRequiredNetworkType(NetworkType.CONNECTED)
- .build()
+ // 仅在特定时间执行(每天指定时间)
+ // 可根据需要设置多个不同时间点的提醒
+ //ReminderWorker.setupScheduledWorker(this, 9, 50) // 上午9:00
+ ReminderWorker.setupScheduledWorker(this, 10, 50) // 下午13:50
- // 创建周期性工作请求
- val reminderWorkRequest = PeriodicWorkRequestBuilder<ReminderWorker>(
- ReminderWorker.REPEAT_INTERVAL,
- ReminderWorker.REPEAT_INTERVAL_TIME_UNIT
- )
- .setConstraints(constraints)
- .addTag("reminder_worker")
- .build()
-
- // 使用 REPLACE 策略确保新配置生效
- WorkManager.getInstance(this).enqueueUniquePeriodicWork(
- "reminder_work",
- ExistingPeriodicWorkPolicy.REPLACE,
- reminderWorkRequest
- )
+ // 不再使用周期性轮询和立即执行的方式
}
}
\ No newline at end of file
--
Gitblit v1.9.3