32

I dont want to add the year or month.Just the hour , minutes and seconds for each day. How to use it the Calendar object to do it ? This is my code

// get a Calendar object with current time
Calendar cal = Calendar.getInstance();
// add 5 minutes to the calendar object

cal.add(Calendar.HOUR, 4);
cal.add(Calendar.MINUTE, 40);




Intent i = new Intent(this, Receiver.class);
i.putExtra("alarm_message", "O'Doyle Rules!");
// In reality, you would want to have a static variable for the request code instead of 192837
PendingIntent sender = PendingIntent.getBroadcast(this, 192837, i, PendingIntent.FLAG_UPDATE_CURRENT);

// Get the AlarmManager service
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
Chetan
  • 1,141
  • 2
  • 15
  • 36

2 Answers2

63

try using

calendar.set(Calendar.HOUR_OF_DAY, 4);
calendar.set(Calendar.MINUTE, 40);
calendar.set(Calendar.SECOND, 0);
nadav
  • 646
  • 6
  • 2
14

try this too

cal.set(2013,2,7,15,42,30);

Note: Months value is MonthNumber-1 (Jan is 0, Feb is 1 and so on).

Saif Hamed
  • 1,084
  • 1
  • 12
  • 17