How to use Alarm Manager for birthday reminder in Android? the date is read from the SQLite database

12,983

Hey this is how to set alarm on android AlarmManager to spesific date (android alarmmanager set alarm on date) I have been searching all over for this. pay attention to the value of the month!!

Calendar cal = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault());
//cal.add(Calendar.SECOND, 10);

cal.set(Calendar.DATE,19);  //1-31
cal.set(Calendar.MONTH,Calendar.DECEMBER);  //first month is 0!!! January is zero!!!
cal.set(Calendar.YEAR,2012);//year...

cal.set(Calendar.HOUR_OF_DAY, 16);  //HOUR
cal.set(Calendar.MINUTE, 39);       //MIN
cal.set(Calendar.SECOND, 10);       //SEC


// Create a new PendingIntent and add it to the AlarmManager
Intent intent = new Intent(MainActivity.this, alarmAct.class);
PendingIntent pendingIntent = PendingIntent.getService(MainActivity.this, 0,intent, 0);

//or if you start an Activity
//PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0,intent, 0);

AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
Share:
12,983

Related videos on Youtube

Vishal Sharma
Author by

Vishal Sharma

Experienced Android developer, having approx 9+ years of experience in Android Application Development. Love to learn new things.

Updated on September 15, 2022

Comments

  • Vishal Sharma
    Vishal Sharma over 1 year

    What to use to set alarm repeating yearly?

  • Vishal Sharma
    Vishal Sharma over 11 years
    what should be used ? whether Service or a broadcast Receiver? to receive intent here?
  • Vishal Sharma
    Vishal Sharma over 11 years
    there i wants to compare time(database and current time);
  • Vishal Sharma
    Vishal Sharma over 11 years
    and also this code is even not calling the broad cast service