AlarmManager的一些方法

2021-07-07 04:09:20 字數 1241 閱讀 1322

呼叫重複執行方法,可指定具體起始時間

calendar calendar = calendar.getinstance();

calendar.settimeinmillis(system.currenttimemillis());

calendar.settimezone(timezone.gettimezone("gmt+8")); // 這裡時區需要設定一下,不然會有8個小時的時間差

calendar.set(calendar.year,2015);

calendar.set(calendar.month,calendar.november);//

calendar.set(calendar.day_of_month, 12);

calendar.set(calendar.hour_of_day, 16);

calendar.set(calendar.minute, 18);

calendar.set(calendar.second, 0);

calendar.set(calendar.millisecond, 0);

alarmmanager manager = (alarmmanager)getsystemservice(alarm_service);

manager.setrepeating(alarmmanager.rtc_wakeup,

calendar.gettimeinmillis(), 10*1000, sender);

在onreceiver裡做一些具體操作

public class alarmreceiver extends broadcastreceiver 

}

經過測試安卓原生4.4系統 殺不死 但是小公尺和oppo會殺死 

alarmmanager.rtc,硬體鬧鐘,不喚醒手機(也可能是其它裝置)休眠;當手機休眠時不發射鬧鐘。

alarmmanager.rtc_wakeup,硬體鬧鐘,當鬧鐘發躰時喚醒手機休眠;

alarmmanager.elapsed_realtime,真實時間流逝鬧鐘,不喚醒手機休眠;當手機休眠時不發射鬧鐘。

alarmmanager.elapsed_realtime_wakeup,真實時間流逝鬧鐘,當鬧鐘發躰時喚醒手機休眠;

需要注意的是如果開始時間是指定的具體時間的時候,用 rtc模式才可以,用elapsed模式是無法生效的

關於AlarmManager的一些筆記

1 傳入的intent會被廣播傳輸 2 設定鬧鐘之後會在手機休眠狀態也維持,除非關機或重啟之後 3 onreceive 方法正在執行時,alarmmanager會獲得系統的cpu喚醒鎖,保證期間手機不休眠 4 setexactandallowwhileidle 5 setrepeating int ...

一些人,一些事,一些

我覺得這是國內it企業浮躁和傳統的官本位性質決定的,導致國內企業都本末倒置。要想改變命運,我覺得有以下出路 1.不做技術了,改做混混 混混的概念很廣泛的,比如銷售 經理 幹部 皮包公司之類其實都屬於這類。中國就是這樣,越浮越掙錢,只有混混才能發財。要不更進一步,做流氓,廣義的流氓,也很不錯。2.專心...

關於RemoteView 的一些字型的一些問題

最近在做乙個 在notification 新增 天氣通知的小部分 發現困擾在 如何給 remoteview 中的字型 作修改 大家都知道 textview 設定字型 在xml 中 可以 設定 3種 而其他字型的設定 需要通過 typeface 去設定 具體 將字型放置在asset 資料夾中 type...