指定时间的报警服务

发布于 2024-11-18 11:05:47 字数 106 浏览 2 评论 0原文

我需要根据DB中的时间值提示警报。我经历了很多例子,但让我感到困惑。任何机构都可以帮助设置给定时间的重复闹钟,例如 2011-07-03 02:00:00:000 。并且应该以 5 分钟的间隔重复。

I need to prompt alarm according to the time values in DB. I came through lot of examples but confusing me. Could any body help to set a repeating alarm for given time like 2011-07-03 02:00:00:000 . and it should repeat for 5mints interval.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

很快妥协 2024-11-25 11:05:47

我建议你创建一个服务。该服务可以使用 AlarmManager 类读取数据库并设置警报。您可以根据您的用途使用 AlarmManager 的 set() 或 setRepeating() 方法。 http:// /developer.android.com/reference/android/app/AlarmManager.html#set%28int,%20long,%20android.app.PendingIntent%29

这是 AlarmManager 的示例 用法。

    long triggerAtTime = SystemClock.elapsedRealtime() + triggerAfterTime;
    AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent i = new Intent(context, YourAlarmReceiver.class);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);

    mgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, pi);

YourAlarmReceiver 类(通常)可以是一个 BroadcastReceiver,您的逻辑将在警报触发时发生。

I suggest you create a service. The service can read the database and set the alarm using AlarmManager class. You can use the AlarmManager's set() or setRepeating() methods based on your use. http://developer.android.com/reference/android/app/AlarmManager.html#set%28int,%20long,%20android.app.PendingIntent%29

here is a sample of AlarmManager usage.

    long triggerAtTime = SystemClock.elapsedRealtime() + triggerAfterTime;
    AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent i = new Intent(context, YourAlarmReceiver.class);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);

    mgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, pi);

YourAlarmReceiver class (usually) can be a BroadcastReceiver where your logic goes on what happens when the alarm is triggered.

浅浅淡淡 2024-11-25 11:05:47

日历应用程序没有公共 API,但由于它是 Google 日历的本机 UI,因此您可以通过其 GData API 将事件推送到 Google 日历。

您可以使用 AlarmManager 类

    AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);  
         Calendar calendar = Calendar.getInstance();      
     calendar.setTimeInMillis(System.currentTimeMillis()); 
          calendar.add(Calendar.SECOND, 10);        
   alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);

There is no public API for the Calendar application, though since it is a native UI for a Google Calendar, you could push an event over to the Google Calendar via its GData API.

You can use AlarmManager class

    AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);  
         Calendar calendar = Calendar.getInstance();      
     calendar.setTimeInMillis(System.currentTimeMillis()); 
          calendar.add(Calendar.SECOND, 10);        
   alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文