- 浏览: 275987 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
jasonking412:
鄙视抄袭,都TMD一样的。
Openfire red5.war下载已经配置 -
xhg19901120:
有没有下载地址啊
【转】Android 多级菜单 -
yxl2005play:
为什么是404?博主,求解
Openfire red5.war下载已经配置 -
tan2416:
回复看看。。。。。
实现在popwindow中展示listview列表 -
liufeng7600:
你好,求教: 我可不可以在pc上用web浏览器访问 Andr ...
android中实现JavaScript与Java之间实现互相调用
AlarmManager的作用文档中的解释是:在特定的时刻为我们广播一个指定的Intent。简单的说就是我们设定一个时间,然后在该时间到来时,AlarmManager为我们广播一个我们设定的Intent。
对应AlarmManager更深层的了解可以参考:
http://www.programbbs.com/doc/5888.htm
http://jinguo.iteye.com/blog/799778
android提供了四种类型的闹钟:
❑ ELAPSED_REALTIME
在指定的延时过后,发送广播,但不唤醒设备。
❑ ELAPSED_REALTIME_WAKEUP
在指定的演示后,发送广播,并唤醒设备
延时是要把系统启动的时间SystemClock.elapsedRealtime()算进去的,具体用法看代码。
❑ RTC
在指定的时刻,发送广播,但不唤醒设备
❑ RTC_WAKEUP
在指定的时刻,发送广播,并唤醒设备
AlarmManager提供的方法:
❑ void set(int type, long triggerAtTime, PendingIntent operation)
设置一个闹钟
❑ void setRepeating(int type, long triggerAtTime, long interval, PendingIntent operation)
设置一个会重复的闹钟
❑ void setInexactRepeating(int type, long triggerAtTime, long interval, PendingIntent operation)
设置一个重复闹钟的不精确版本,它相对而言更节能(power-efficient)一些,因为系统可能会将几个差不多的闹钟合并为一个来执行,减少设备的唤醒次数。
内置的几个interval为:
INTERVAL_FIFTEEN_MINUTES
INTERVAL_HALF_HOUR
INTERVAL_HOUR
INTERVAL_HALF_DAY
INTERVAL_DAY
如果你将其设为DAY,那么可能这一天中的所有闹钟都会被合并掉。
❑ void cancel(PendingIntent operation)
取消一个设置的闹钟
❑ void setTimeZone(String timeZone)
设置系统的默认时区。需要android.permission.SET_TIME_ZONE权限
- // 首先创建Receiver
- public class AlarmReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- Toast.makeText(context, "alarm" , Toast.LENGTH_SHORT).show();
- }
- }
- // manifest中申明,并不需要intent-filter,我们是明确指定发到哪个receiver的
- < receiver android:name = "yuan.receivers.AlarmReceiver" />
PendingIntent:简单的说就是在Intent上在加个指定的动
作。Intent的话,我们还需要在执行startActivity、startService或sendBroadcast才能使Intent有用。而
PendingIntent的话就是将这个动作包含在内了,如PendingIntent.getBroadcast就包含了sendBroadcast
的动作。
5s后发送指定广播
- AlarmManager alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
- Intent intent = new Intent(getApplicationContext(), AlarmReceiver. class );
- int requestCode = 0 ;
- PendingIntent pendIntent = PendingIntent.getBroadcast(getApplicationContext(),
- requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
- // 5秒后发送广播,只发送一次
- int triggerAtTime = SystemClock.elapsedRealtime() + 5 * 1000 ;
- alarmMgr.set(AlarmManager.ELAPSED_REALTIME, triggerAtTime, pendIntent);
5s后发送指定广播,然后每个10秒重复发送广播
- AlarmManager alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
- Intent intent = new Intent(getApplicationContext(), AlarmReceiver. class );
- int requestCode = 0 ;
- PendingIntent pendIntent = PendingIntent.getBroadcast(getApplicationContext(),
- requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
- // 5秒后发送广播,然后每个10秒重复发广播。广播都是直接发到AlarmReceiver的
- int triggerAtTime = SystemClock.elapsedRealtime() + 5 * 1000 ;
- int interval = 10 * 1000 ;
- alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, interval, pendIntent);
取消一个闹钟
- AlarmManager alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
- Intent intent = new Intent(getApplicationContext(), AlarmReceiver. class );
- PendingIntent pendIntent = PendingIntent.getBroadcast(getApplicationContext(),
- 0 , intent, PendingIntent.FLAG_UPDATE_CURRENT);
- // 与上面的intent匹配(filterEquals(intent))的闹钟会被取消
-
alarmMgr.cancel(pendIntent);
发表评论
-
singleTop和singleTask有什么区别?(活动 Activity 四种加载模式)
2013-03-22 17:50 1384singleTop要求如果创建intent的时候栈顶已经有要 ... -
onCreateOptionsMenu和onPrepareOptionsMenu的差別在哪呢?
2012-09-17 16:25 1571在做菜单的功能,发现 ... -
android状态栏中多个通知冲突的问题
2012-09-11 17:49 6405网上看到的解决办法: 如果用相同的通知id, 该怎么 ... -
Anroid 异常:is not valid; is your activity running?
2012-08-29 11:23 1149是由于有activity时依附于另一个activity的, ... -
Android 如何让EditText不自动获取焦点
2012-08-15 11:42 3637在项目中,一进入一个页面, EditText默认就会自动获取焦 ... -
Animation
2012-07-31 23:51 801前面定义旋转,移动,缩放到什么程度, 后面是轴承点,根据这个点 ... -
删除android ScrollView边界阴影方法
2012-07-19 10:26 1285XML文件中添加以下方法: android:fadin ... -
Android的webview加载本地html、本apk内html和远程URL
2012-07-19 09:56 1653... -
如何在mac中创建android adb 环境
2012-05-03 23:31 1746Create an environment variable ... -
用Android代码实现打开USB调试
2012-03-20 17:52 9066打开Android手机的USB调试对于使用豌豆夹、调试程序等来 ... -
android ROM RAM 内部存储 系统存储 系统缓存区别
2012-03-16 14:58 5242内部存储┐ 系统存储├─物理位置是位于手机内部的非易失性存储 ... -
Android 读取MCC, MNC
2012-03-12 13:46 13240TelephonyManager telManager = ( ... -
Android 动画详解
2012-03-09 14:09 3696Tween动画又称“补间动画”、“中间动画”,这并不重要,就好 ... -
Region.Op
2012-02-29 17:37 929//INTERSECT 取两者交集,默认的方式 //DIF ... -
Eclipse中LogCat突然停止工作的解决
2012-01-18 17:34 1670... -
sdcard
2011-12-29 13:28 1021把文件放入SD卡 使用Activity的o ... -
Android 中自定义属性(attr.xml,TypedArray)的使用!
2011-10-07 17:39 971在xml 文件里定义控件的属性,我们已经习惯了android ... -
Android 中自定义View的应用.
2011-10-07 17:38 808大家好我们今天的教程 ... -
android Canvas类介绍
2011-09-23 11:01 1282package com.yarin.android.E ... -
Android SeekBar
2011-09-15 15:40 1268SeekBar可以作为音乐播放器的进度指示和调整工具,音量调整 ...
相关推荐
android AlarmManager 多个 定时 重复提醒,我这篇博文的源码。
http://blog.csdn.net/two_water/article/details/52004414 博客Demo
Android AlarmManager
Andorid AlarmManager的使用,通过这个实例可以变换实现闹钟功能
AlarmManager 闹铃(支持重启) 设置多个闹铃 备注详细
AlarmManager提供了访问系统闹钟的服务。它允许你安排你的应用在未来某个时间点运行。这就相当于定时任务。对于少于60s的定时任务,不推荐使用AlarmManager,可以使用更高效的的Handler来处理频发的任务。
Android 后台运行 定时器 AlarmManager Service
Android_AlarmManager一些简单的操作
本示例通过AlarmManager 全局定时器 实现 定时更换壁纸
本文将讲解一下如何使用AlarmManager实现定时提醒功能。 闹钟配置 周期闹钟 Intent intent = new Intent(); intent.setAction(GlobalValues.TIMER_ACTION_REPEATING); PendingIntent sender = PendingIntent....
android安卓闹铃服务AlarmManager的使用
Android下AlarmManager的小闹钟程序,初学可以看看
使用AlarmManager实现Android定时任务(闹钟),解决了Android版本更新导致的定时不准确问题。Demo源码
app进程中,需要实现一个定时任务,只要设备处于开机状态,每隔半个小时,就需要定时向服务器上传一次位置信息,并且只要是有网络和获取到GPS信号,进程不能死,如果进程死掉了,需要自动重启。
Android中使用AlarmManager设置闹钟示例代码
1. 通过 AlarmManager 来设置定制任务 2. 用广播去启动Service 3. Service中onStartCommand()方法执行任务
本示例为女性贴身看护 程序 运用AlarmManager、DatePicker、TimePicker提供了以下功能: 1. 设置前一次MC的日期 2. 设置MC的周期天数 3. 设置每日提醒的时间
先说下需求吧, 这个是服务器端设定几个时间段,比如说 周一,周三 的下午15点。 然后让用户来勾选。如果用户选择了这个时间段,那么每个周一,周三的下午15点都给用户一个提醒
AlarmManager定时设置提醒,发送通知