在android系统开始报警服务 [英] Starting alarm service in android

查看:126
本文介绍了在android系统开始报警服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序要使用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

这篇关于在android系统开始报警服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆