在android系统开始报警服务系统、android

由网友(天生傲骨怎能服输)分享简介:在我的应用程序要使用time.I'm的特定时期报警服务从用户接受开始时间和结束时间值并将其保存在数据库中,现在我要开始在启动时也应该警报器的报警服务在由user.I'm新这个话题,并不能规定结束时间走下车来了解如何实现这个...任何帮助将AP preciated.Thankü.. In my application...

在我的应用程序要使用time.I'm的特定时期报警服务从用户接受开始时间和结束时间值并将其保存在数据库中,现在我要开始在启动时也应该警报器的报警服务在由user.I'm新这个话题,并不能规定结束时间走下车来了解如何实现这个...任何帮助将AP preciated.Thankü..

In my application i want to use alarm service for specific period of time.I'm taking start time and end time values from user and saving it in database,Now i want to start a alarm service at start time and alarm should go off at end time specified by user.I'm new to this topic and not able to understand how to implement this...Any help will be appreciated.Thank u..

推荐答案

这是如何实现的警报经理。但你需要了解Android中也Calendar对象。

This is how you implement an alarm manager. But you will need to read about Calendar object in android also.

 String alarm = Context.ALARM_SERVICE;
 Calendar calendar = Calendar.getInstance();

 calendar.set(Calendar.HOUR_OF_DAY, 8);//Just an example setting the alarm for the 8th hour of a day.
  calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND,0);
calendar.set(Calendar.MILLISECOND, 0);



AlarmManager am = (AlarmManager)getActivity().getSystemService(alarm);
//This is the intent that is launched when the alarm goes off.
                    Intent intent = new Intent("WAKE_UP");

PendingIntent sender = PendingIntent.getBroadcast(getActivity(), 0, intent, 0);



//If the user wants the alarm to repeat then use AlarmManager.setRepeating if they just want it one time use AlarmManager.set().

    am.setRepeating(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis() , AlarmManager.INTERVAL_DAY, sender);




                    }

此外,你需要注册一个广播接收到报警时设置它关闭,除了意图。创建广播reciever并在清单注册它来接收从报警的意图。 http://www.vogella.de/articles/AndroidServices/article.html

下面是一个伟大的教程,以帮助您更好地了解

Here is a great tutorial to help you understand better

阅读全文

相关推荐

最新文章