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);
Related videos on Youtube
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, 2022Comments
-
Vishal Sharma over 1 year
What to use to set alarm repeating yearly?
-
Vishal Sharma over 11 yearswhat should be used ? whether Service or a broadcast Receiver? to receive intent here?
-
Vishal Sharma over 11 yearsthere i wants to compare time(database and current time);
-
Vishal Sharma over 11 yearsand also this code is even not calling the broad cast service