Android編程實現(xiàn)PendingIntent控制多個鬧鐘的方法
本文實例講述了Android編程實現(xiàn)PendingIntent控制多個鬧鐘的方法。分享給大家供大家參考,具體如下:
要用 android.app.PendingIntent.getBroadcast(Context context, int requestCode, Intent intent)來實現(xiàn)控制多個鬧鐘,關(guān)鍵點在于其中的一個參數(shù)requestCode.
舉例說明如下:
public void setClock(){
if(lva.ids.equals("")||lva.ids==null||lva.ids.length()<0){
Toast.makeText(AlarmTest.this, "請選擇要設(shè)定的鬧鐘!", Toast.LENGTH_LONG).show();
}
else{
/*到這里了,重點是怎樣獲取時間和分鐘并傳入其中*/
r=dao.getAll(lva.ids.replaceAll("[\\p{Punct}\\p{Space}]+", ""));
Toast.makeText(AlarmTest.this, r.getId()+"時:"+r.getHour()+"分:"+r.getMinute(), Toast.LENGTH_LONG).show();
c.setTimeInMillis(System.currentTimeMillis());
c.set(Calendar.HOUR_OF_DAY, Integer.parseInt(r.getHour()));
c.set(Calendar.MINUTE, Integer.parseInt(r.getMinute()));
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
Intent i=new Intent(AlarmTest.this,CallAlarm.class);
PendingIntent sender=PendingIntent.getBroadcast(AlarmTest.this, r.getId(), i, 0);
AlarmManager am=(AlarmManager)getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), sender);
}
希望本文所述對大家Android程序設(shè)計有所幫助。
相關(guān)文章
Android實現(xiàn)WebView點擊攔截跳轉(zhuǎn)原生
這篇文章主要介紹了Android實現(xiàn)WebView點擊攔截跳轉(zhuǎn)原生,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03
Android?獲取實時網(wǎng)速實現(xiàn)詳解
這篇文章主要為大家介紹了Android?獲取實時網(wǎng)速實現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-11-11
解析:繼承ViewGroup后的子類如何重寫onMeasure方法
本篇文章是對繼承ViewGroup后的子類如何重寫onMeasure方法進行了詳細的分析介紹,需要的朋友參考下2013-06-06
Android Manifest中meta-data擴展元素數(shù)據(jù)的配置與獲取方式
這篇文章主要介紹了Android Manifest中meta-data擴展元素數(shù)據(jù)的配置與獲取方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03
Android實現(xiàn)電子羅盤(指南針)方向傳感器的應(yīng)用
今天小編就為大家分享一篇關(guān)于Android實現(xiàn)電子羅盤(指南針)方向傳感器的應(yīng)用,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-03-03

