使用报警管理器来设置报警的Android [英] use Alarm Manager to set alarm in Android
问题描述
在我的Android应用程序,我想在特定的时间由用户输入一些消息的时间设置报警。
我如何使用广播接收器设置报警?是否有可能弹出一个消息比默认的消息?
其他指定的时间 AlarmManager ALR =(AlarmManager)this.getSystemService(ALARM_SERVICE);
意向意图=新意图(YourAction);
的PendingIntent的PendingIntent = PendingIntent.getBroadcast(背景下,0 / ** SOM唯一的ID * /,意向,0);
alr.set(AlarmManager.ELAPSED_REALTIME,0 / **这里是一个延迟* /的PendingIntent);
之后,你应该创建一个广播接收器
,将获得与行动=YourAction
意图。从接收器就可以启动,这将shoiw您与您的自定义消息对话框的活动。见<一href=\"http://stackoverflow.com/questions/4450347/how-to-lauch-an-3rd-application-automatically-when-the-android-phone-is-switched/4450405#4450405\">this答案,看看如何设置的广播接收器。
In my Android application I would like to set alarm at a particular time with some message for time entered by user.
How can I set alarm using broadcast receiver? Is it possible to pop up a message on the specified time other than the default message?
AlarmManager alr = (AlarmManager) this.getSystemService(ALARM_SERVICE);
Intent intent = new Intent("YourAction");
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0/** som unique id*/, intent, 0);
alr.set(AlarmManager.ELAPSED_REALTIME, 0/** here is a delay*/, pendingIntent);
after that you should create a BroadcastReceiver
, that will get intent with action = "YourAction"
. From that receiver you can start an activity which will shoiw you the dialog with your custom messages. See this answer to see how to setup the BroadcastReceiver.
这篇关于使用报警管理器来设置报警的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!