简体   繁体   English

我如何在最新的Android手机上运行后台工作(如闹钟)

[英]How can I run background work like alarm on latest android phones

I have some task like medicine reminder. 我有一些任务,例如提醒药物。 Everyday reminder schedule is stored in the SQLite database. 日常提醒计划存储在SQLite数据库中。 Reminders are every day different. 提醒每天都不同。

For example 例如

21.02.19 - 08:00, 12:00, 19:00 19.02.19-08:00,12:00,19:00

22.02.19 - 08:30, 12:30, 19:30 22.02.19-08:30,12:30,19:30

... ...

Minimum android 4.4 (Api 19) Target android 9.0 (Api 28) 最低android 4.4(Api 19)目标android 9.0(Api 28)

I read about WorkManager, JobScheduler, JobIntentService, FirebaseJobDispathcer, Alarm manager. 我阅读了有关WorkManager,JobScheduler,JobIntentService,FirebaseJobDispathcer,警报管理器的信息。 There is a lot of API s to do that. 有很多API可以做到这一点。

Firstly I tried to check time with interval every minute using alarm manager. 首先,我尝试使用警报管理器每分钟检查一次时间。 But it is not working properly in latest android. 但在最新的android系统中无法正常工作。 There have background restrictions, Doze Mode and standby. 有背景限制,打ze模式和待机状态。 Then I tried JobScheduler but it does not work devices under 21 API. 然后,我尝试了JobScheduler,但它在21 API下无法正常工作。 And FirebaseJobDispatcher required google play service, it is not a good idea. 而且FirebaseJobDispatcher需要Google Play服务,这不是一个好主意。 Finally, I find WorkManager. 最后,找到WorkManager。 But in workmanager and jobscheduler have minimum interval like 15 minutes. 但是在工作经理和工作计划者中,最小间隔为15分钟。

How can I make background service to remind users in specific exact time every day? 如何进行后台服务,以每天的确切时间提醒用户? I am not using the internet, GPS, location. 我没有使用互联网,GPS和位置信息。 Only get time from SQLite and remind in exact time. 仅从SQLite获取时间并提醒准确时间。

In a few months ago, I developed medicine reminder app too. 在几个月前,我还开发了药物提醒应用程序。

I use 'run the daily job in 0:00AM using android-job ' methods to achieve this. 我使用“使用android-job在0:00 AM运行日常工作 ”方法来实现此目的。

In DailyJob, we have this process. 在DailyJob中,我们有此过程。

  1. Grab some time information in DB 在数据库中获取一些时间信息
  2. Convert (desired time - now time) into milliseconds. 将(所需时间-现在时间)转换为毫秒。 if now time is 00:15AM and desire time is 07:00AM, it will be 24300000ms. 如果现在时间是00:15 AM并且期望时间是07:00 AM,那么它将是24300000ms。
  3. Run exact job with converted milliseconds in Step 2. 在步骤2中以转换后的毫秒数运行确切的作业。

In Exact job, we display a notification to the user. 在“确切的工作”中,我们向用户显示通知。

I can't attach code because of privacy, but you can achieve the same things. 由于隐私原因,我无法附加代码,但是您可以实现相同的目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在简单的闹钟应用程序中创建列表项,该应用程序可以在 android 中“创建/编辑闹钟”设置屏幕 - how to create List item like in simple alarm application that can"create/edit alarm" settings screen in android 如何在android手机中运行android聊天应用程序? - How to run android chat application in android phones? 如何获取多部Android手机的位置? - How can i get the location of multiple android phones? 如何在android的后台运行蓝牙连接? - How can I run bluetooth connection in the background in android? 如何在Android中触发闹钟,即播放闹钟铃声? - How can I set off an alarm i.e. play an alarm tone in Android? 如何在 Android 中使用 AlarmManager 设置多个警报? - How can I set more than one alarm with AlarmManager in Android? 如何将我的 android 工作室项目设置为我的手机背景? - How do I set my android studio project as my phones background? 我需要创建一个可以在所有智能手机上运行的智能手机应用程序,我该怎么做? - I need to create a smart phone application that could be run on all smart phones, How can i do this? 如何在Android手机上访问相机? - How do I access the camera on Android phones? 如何使用Swing运行后台任务? - How can I run background tasks with Swing?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM