Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to develop Android Alarm application

Tags:

android

I tried to develop a sample Alarm Application. I searched Google and SC, most of their examples confused. How can I create an alarm application with the following requirements,

  1. In My Home screen i have a button, like "START ALARM", when i click the button a time picker must enable.

  2. I select the time as I wish, once I pick the time, the alarm icon will enabled on widget. (For example if we set the alarm in default mobile Alarm application, the icon will be enabled, that indicates the alarm is set).

  3. When the set time is reached (the time which is set form the TimePicker app), the alarm will beep.

These are my requirements, I finished the first two points, but I'm still struggling on setting the alarm.

like image 570
Aerrow Avatar asked Feb 09 '12 09:02

Aerrow


People also ask

How the alarm is created in Android?

Go to MainActivity. In MainActivity. java class onToggleClicked( ) method is implemented in which the current hour and the minute is set using the calendar. Alarm services are implemented using AlarmManager class.

What is alarm in mobile application development?

Android AlarmManager allows you to access system alarm. By the help of Android AlarmManager in android, you can schedule your application to run at a specific time in the future. It works whether your phone is running or not.

How do you set a custom alarm on Android?

Open your phone's Clock app . At the bottom, tap Alarm. Pick an alarm. To add an alarm, tap Add .


2 Answers

If you want to make things interesting, you can try to create one without a possibility of dismissing/snoozing. I made this a while ago, you can read about it in this tutorial:

Alarm Application in Android (Tutorial using AlarmManager)

And test the app functionality by downloading this app: Oversleeper on Google Play

like image 37
Vladimir Marton Avatar answered Nov 16 '22 03:11

Vladimir Marton


Take a look at AlarmManager. And, If you want to use alarm simultaneously you must use Service class for that. And, see below sample code -

public class OnBootReceiver extends BroadcastReceiver {
  private static final int PERIOD=300000;  // 5 minutes

  @Override
  public void onReceive(Context context, Intent intent) {
    AlarmManager mgr =
      (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
    Intent i=new Intent(context, OnAlarmReceiver.class);
    PendingIntent pi=PendingIntent.getBroadcast(context, 0, i, 0);
    mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 
      SystemClock.elapsedRealtime()+60000, PERIOD, pi);
  }

This will repeat the alarm with every 6 Mins. See Scheduling Repeating Alarms document.

like image 92
Praveenkumar Avatar answered Nov 16 '22 03:11

Praveenkumar