FCM-OnDeviceNotificationScheduler本地通知调度方案

FCM 的本地通知调度方案里,FCM-OnDeviceNotificationScheduler这个项目还挺实用的。用FCM接消息,用AlarmManager定时,用WorkManager兜底跑任务,三件套结合得挺顺。想学怎么把远程推送跟本地定时串起来的,看看它就对了。

用的是Kotlin写的,代码简洁,空安全和扩展函数这些优势都发挥出来了。要是你之前只用BroadcastReceiver或者自己手搓Handler写定时,不如试试这个方案,稳妥还兼容新版本。

AlarmManager主要负责“什么时候干活”,适合精确时间点。像设置明天 8 点提醒用户打卡,就可以交给它搞定。但它有个小毛病:系统杀进程。

这时候WorkManager就顶上了。它有持久性,设备重启后也能照常执行任务,而且还能判断当前设备状态,比如有没有网、是不是在充电,灵活度高,可靠性强。

配合使用后,你可以先用FCM触发服务端的指令,比如“在某时间点通知用户有新活动”。客户端接到消息后,用AlarmManager设置任务时间,到点再让WorkManager去执行真正的通知逻辑。

想试试可以直接拉项目代码看看:结构清晰,MainActivity负责初始化,FirebaseMessagingService消息,Worker执行任务。基本照着抄下来都能跑。

如果你对后台服务还不太熟,可以顺带看看这篇:Android 后台服务入门,也挺有的。

FCM + AlarmManager + WorkManager这种组合比较推荐,适合做带推送通知的定时提醒。适合课程打卡、活动开始提醒、用户唤醒这些场景。如果你也在做这类功能,值得研究一下。

zip
FCM-OnDeviceNotificationScheduler-master.zip 预估大小:55个文件
folder
FCM-OnDeviceNotificationScheduler-master 文件夹
file
gradlew.bat 2KB
file
gradlew 5KB
file
gradle.properties 1KB
folder
.github 文件夹
file
FUNDING.yml 575B
folder
output 文件夹
file
Demo.mp4 1018KB
file
Demo.gif 1.6MB
file
LICENSE 1KB
folder
app 文件夹
file
proguard-rules.pro 751B
folder
src 文件夹
folder
test 文件夹
folder
java 文件夹
folder
com 文件夹
folder
spdroid 文件夹
folder
schedulefcm 文件夹
folder
example 文件夹
file
ExampleUnitTest.kt 366B
folder
androidTest 文件夹
folder
java 文件夹
folder
com 文件夹
folder
spdroid 文件夹
folder
schedulefcm 文件夹
folder
example 文件夹
file
ExampleInstrumentedTest.kt 699B
folder
main 文件夹
folder
res 文件夹
folder
mipmap-xxxhdpi 文件夹
file
ic_launcher.png 9KB
file
ic_launcher_round.png 15KB
folder
drawable-hdpi 文件夹
file
ic_stat_ic_notification.png 308B
folder
drawable-xhdpi 文件夹
file
ic_stat_ic_notification.png 380B
folder
drawable 文件夹
file
ic_launcher_background.xml 5KB
folder
drawable-xxhdpi 文件夹
file
ic_stat_ic_notification.png 544B
folder
mipmap-hdpi 文件夹
file
ic_launcher.png 3KB
file
ic_launcher_round.png 5KB
folder
drawable-v24 文件夹
file
ic_launcher_foreground.xml 2KB
folder
values 文件夹
file
colors.xml 208B
file
strings.xml 238B
file
styles.xml 383B
folder
drawable-mdpi 文件夹
file
ic_stat_ic_notification.png 237B
folder
mipmap-xxhdpi 文件夹
file
ic_launcher.png 6KB
file
ic_launcher_round.png 10KB
folder
mipmap-mdpi 文件夹
file
ic_launcher.png 2KB
file
ic_launcher_round.png 3KB
folder
drawable-anydpi-v24 文件夹
file
ic_stat_ic_notification.xml 719B
folder
mipmap-xhdpi 文件夹
file
ic_launcher.png 4KB
file
ic_launcher_round.png 7KB
folder
mipmap-anydpi-v26 文件夹
file
ic_launcher_round.xml 272B
file
ic_launcher.xml 272B
folder
layout 文件夹
file
activity_main.xml 837B
folder
java 文件夹
folder
com 文件夹
folder
spdroid 文件夹
folder
schedulefcm 文件夹
folder
example 文件夹
folder
ui 文件夹
file
MainActivity.kt 1KB
folder
util 文件夹
file
NotificationUtil.kt 2KB
file
SettingUtil.kt 286B
folder
fcm 文件夹
file
NotificationBroadcastReceiver.kt 1KB
file
MyFirebaseMessagingService.kt 3KB
file
ScheduledWorker.kt 1KB
file
AndroidManifest.xml 2KB
file
.gitignore 7B
file
build.gradle 1KB
folder
gradle 文件夹
folder
wrapper 文件夹
file
gradle-wrapper.jar 53KB
file
gradle-wrapper.properties 232B
folder
.idea 文件夹
folder
codeStyles 文件夹
file
Project.xml 4KB
file
codeStyleConfig.xml 142B
file
gradle.xml 680B
file
runConfigurations.xml 564B
file
misc.xml 611B
file
vcs.xml 180B
file
.gitignore 208B
file
README.md 7KB
file
settings.gradle 46B
folder
.opensource 文件夹
file
project.json 113B
file
build.gradle 718B
...
zip 文件大小:2.29MB