I want to create an alarm object from my application. I am writing a To-Do application which will have an option to set an Alarm on the phone.
I wanna set the Date and Time and also the Label for the alarm.
Calendar c = Calendar.getInstance();
c.setTimeInMillis(System.currentTimeMillis());
c.clear();
c.set(Calendar.YEAR, mYear);
c.set(Calendar.MONTH, mMonth);
c.set(Calendar.DAY_OF_MONTH, mDay);
c.set(Calendar.HOUR, mHour);
c.set(Calendar.MINUTE, mMinute);
Intent activate = new Intent(this, alaram.class);
AlarmManager alarams ;
PendingIntent alarmIntent = PendingIntent.getBroadcast(this, 0, activate, 0);
alarams = (AlarmManager) getSystemService(this.ALARM_SERVICE);
alarams.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), alarmIntent);
I tried using the above code to set the alarm but am not able to. I dont get any error either 🙁
As @stealthcopter said, the AlarmManager is used to raise an Alarm your application can catch and then do something. Here is a little example I threw together from other posts, tutorials, and work I’ve done.
Main.java
OnAlarmReceiver.java
WakeIntentService.java
AlarmService.java
This example will create a notification on the status bar after 10 seconds.
Hope it helps.
Also First post here 🙂
Oh almost forgot,
AndroidManifest.xml