资源描述:
《android_alarm》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1.设置定时时间文件:packages/apps/alarmclock/src/com/android/alarmclock/Alarms.javaprivatestaticvoidenableAlert(Contextcontext,finalAlarmalarm, finallongatTimeInMillis){ AlarmManageram=(AlarmManager) context.getSystemService(Context.ALARM_
2、SERVICE); ... am.set(AlarmManager.RTC_WAKEUP,atTimeInMillis,sender); ... }由闹钟管理器设置定时时间。2.闹钟管理器文件:frameworks/base/core/java/android/app/AlarmManager.javapublicstaticfinalintRTC_WAKEUP=0; publicstaticfinalintRTC=1; publicstatic
3、finalintELAPSED_REALTIME_WAKEUP=2;publicstaticfinalintELAPSED_REALTIME=3; AlarmManager(IAlarmManagerservice){ mService=service; } publicvoidset(inttype,longtriggerAtTime,PendingIntentoperation){ try{ mService.set(type,triggerAtTime
4、,operation); }catch(RemoteExceptionex){ } }将type,triggerAtTime,operation等参数转向闹钟管理器服务。3.闹钟管理器服务文件:frameworks/base/services/java/com/android/server/AlarmManagerService.java3.1定时设置publicAlarmManagerService(Contextcontext){ mDescriptor=init();
5、 ...}publicvoidset(inttype,longtriggerAtTime,PendingIntentoperation){ setRepeating(type,triggerAtTime,0,operation); } publicvoidsetRepeating(inttype,longtriggerAtTime,longinterval, PendingIntentoperation){ if(operation==n
6、ull){ Log.w(TAG,"set/setRepeatingignoredbecausethereisnointent"); return; } synchronized(mLock){ Alarmalarm=newAlarm(); alarm.type=type; alarm.when=triggerAtTime; alarm.repeatInterval=inte
7、rval; alarm.operation=operation; //Removethisalarmifalreadyscheduled. removeLocked(operation); if(localLOGV)Log.v(TAG,"set:"+alarm); intindex=addAlarmLocked(alarm); if(index==0){ setL
8、ocked(alarm); } } }privatevoidsetLocked(Alarmalarm) { if(mDescriptor!=-1) { set(mDescriptor,alarm.type,(alarm.when*1000*1000)); }