NewBIe
NewBIe

Reputation: 299

How to design a scheduler alarm system using android

I am creating an android app which will serve as a scheduler. The client is allowed to enter all his schedules for the 1 month ahead.

For instance

Monday 22/12/2016 2:30am Go for work Tuesday 23/12/2016 4:00pm Visit a friend .....

Now a user is allowed to enter all this information into the local sqlite database of the app.

Please with this information in the database, would it be possible for the system to send a notification with an alarm to the user interface when the time schedule is due, even when the app has been closed?

I would very glad if someone can give any ideas or links as to how to go about this. Thanks in advance.

Upvotes: 0

Views: 265

Answers (2)

Murtaza Khursheed Hussain
Murtaza Khursheed Hussain

Reputation: 15336

Although the question is couple of months old, but still I want to answer, answer by @Zahan Safallwa is corrent but you need to manage Pending Intent, Request Code, Intent for Pending Intent and Time/delays for alarms. This will increase exponentially if you have multiple alarms. For the purpose I had a wrote a class which will help you out.

Sample Usage: For scheduling

new ScheduleAlarm( context )
  .withRequestCode( REQUEST_CODE )
  .forClass( SomeIntentService.class )
  .withDelay( 0 )
  .withRepeatsIn( TIME_IN_MILLISECONDS )
  .schedule();

Sample Usage:For re-scheduling-Post kitkat

new ScheduleAlarm( context )
  .withRequestCode( REQUEST_CODE )
  .forClass( SomeIntentService.class )
  .withDelay( TIME_IN_MILLISECONDS )
  .withRepeatsIn( TIME_IN_MILLISECONDS )
  .reSchedule();

Sample Usage:Stops alarm

new ScheduleAlarm( context )
  .withRequestCode( REQUEST_CODE )
  .forClass( SomeIntentService.class )
  .stopAlarm();

It is available on GIST

Upvotes: 0

Zahan Safallwa
Zahan Safallwa

Reputation: 3914

Yes it is possible.

You can store you information in sqlite database. Then with data from database you will be able to get the information and set the alarm with Pending intent .

You can set both repeating and non repeating alarm.

Use wake lock permission in the manifest to keep the screen on and awake from lock condition and show your alarm screen with information.

With RingtoneManager it is possible to play some music too when alarm fires.

And most importantly if the phone restarts or put off and then again put on when the boot completes the alarm service will set all your alarm automatically.

Basically these are the main steps to build an alarm system. For an example see below repository in Github

https://github.com/zahansafallwa/AlarmClock

Its a bit of complex coding but this one more or less includes all the possible staffs you can do with alarm manager in android

Upvotes: 1

Related Questions