Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alarm manager in android

I have created simple alarm app. It works fine but, if i change time of device manually then my alarm doesn't work....

This is my code:

    Calendar = Calendar.getInstance();
    //c.add(Calendar.DAY_OF_WEEK,1);
    c.set(Calendar.HOUR_OF_DAY,15);
    c.set(Calendar.MINUTE, 00);
    c.set(Calendar.SECOND, 00);
    c.set(Calendar.MILLISECOND, 0);

    Intent intent = new Intent(HomeActivity.this, MyAlarmService.class);
    pendingIntent = PendingIntent.getService(HomeActivity.this, 0, intent, 0);
    alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, c.getTimeInMillis(), pendingIntent);

Is there any suggestion?

like image 559
Piyush Avatar asked Nov 14 '11 08:11

Piyush


People also ask

How do I set alarm manager on Android?

This example demonstrates how do I implement alarm manager in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do I turn off alarm manager?

You can cancel the alarm like this: Intent intent = new Intent(this, Mote. class); PendingIntent pendingIntent = PendingIntent. getBroadcast(getApplicationContext(), 1253, intent, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.

Where is alarms on my Android phone?

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


1 Answers

[Adding the answer from comment to here]

You need to add a receiver to set the alarm again..on date and time zone change then alarm got reset so use this

<receiver android:name=".AlarmInitReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.TIME_SET" /> <action android:name="android.intent.action.TIMEZONE_CHANGED" /> 
</intent-filter> 
</receiver>
like image 184
Maneesh Avatar answered Oct 12 '22 07:10

Maneesh