使用报警管理器来设置报警的Andr​​oid [英] use Alarm Manager to set alarm in Android

查看:93
本文介绍了使用报警管理器来设置报警的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用程序,我想在特定的时间由用户输入一些消息的时间设置报警。

如何使用广播接收器设置报警?是否有可能弹出一个消息比默认的消息?

其他指定的时间
解决方案

  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.

这篇关于使用报警管理器来设置报警的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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