开发者

android how to set the phone alarm through code

I want to set the alram for phone through program coding. I have an button where by clicking DatePicker come & also time picker. I want what time i set here that ti开发者_运维技巧me should be set in phones alaram. How can I do that . plz give me the answer . Thank you


Please try this....

 Calendar cal = Calendar.getInstance();  
 cal.add(Calendar.DAY_OF_YEAR, 0);     
 cal.set(Calendar.HOUR_OF_DAY, 9);   
 cal.set(Calendar.MINUTE, 01);     
 cal.set(Calendar.SECOND, 0);   
 Intent intent = new Intent(Alarm.this, Alarm1.class);  
 PendingIntent sender = PendingIntent.getBroadcast(this, 1234567, intent, 0); 
 PendingIntent sende2 = PendingIntent.getBroadcast(this, 123123, intent, 0);    
 AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);   
 am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender); 


 am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sende2); 
 Intent intent1 = new Intent(Alarm.this, Alarm1.class);  
 PendingIntent sender1 = PendingIntent.getBroadcast(this, 1234567, intent1, 0);  
 AlarmManager am1 = (AlarmManager) getSystemService(ALARM_SERVICE);
 am1.cancel(sender1);

 b1.setOnClickListener(new View.OnClickListener() {
 public void onClick(View v) {

 Alarm a = new Alarm ();   
 a.setAlarm();         
 b1.setText(prod);  
 }               
 }); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜