0

I'm trying to set an alarm for a particular date and time but so far I've been unsuccessful. As an experiment I'm trying to set it for 10:04am today like so:

Calendar cal = Calendar.getInstance();
        // int currtYear = cal.get( Calendar.YEAR );
        // int minute = cnvrtStrg( splitTime[1] ) - 5;
        // int hour = cnvrtStrg( splitTime[0] );

        cal.setTimeInMillis( System.currentTimeMillis() );
        cal.clear();
        cal.set( 2012, 4, 10, 10, 4 );

        Intent intent = new Intent( passing_info.this, alarm_receiver.class );
        sender = PendingIntent.getBroadcast( this, 0, intent, 0);

        am = (AlarmManager)getSystemService( ALARM_SERVICE );
        am.set( AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),sender );
        Toast.makeText( getApplicationContext(), "Alarm set",Toast.LENGTH_SHORT ).show();

Am I right in how I set it? And why isn't this doing anything? i.e. it doesn't go off ( the receiver class vibrates the phone)

Thanks

P.S. The toast message appears at that bottom

Katana24
  • 8,706
  • 19
  • 76
  • 118

1 Answers1

6

Month is always minus one. Means if you want to give april then use 3 instead of 4 so:

cal.set( 2012, 3, 10, 10, 4 );
Abhi
  • 8,935
  • 7
  • 37
  • 60
  • Thanks mate that worked :P I understand why they do that but it's rather off putting really - there is no 0 month in real life so why put january as it? – Katana24 Apr 10 '12 at 09:18
  • 1
    There is actually yet another interesting question on this: http://stackoverflow.com/questions/344380/why-is-january-month-0-in-java-calendar – dbm Apr 10 '12 at 09:23
  • @Abhi can't for another 1 minute :D – Katana24 Apr 10 '12 at 09:24
  • One last thing, for verification, - say if I wanted the alarm to go off on 11th of April at 05:49:00am would this do it? cal.set( 2012, 3, 11, 5, 49 ) – Katana24 Apr 10 '12 at 09:33