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?
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.
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.
Open your phone's Clock app . At the bottom, tap Alarm. Pick an alarm. To add an alarm, tap Add .
[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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With