0

I am working on application which is get the alarm time from database every 2 AM and then at the specified time the activity shows up, my app works fine, but when I manually change the data/time of the device, previous alarms are triggered and I should prevent to this to happens.

Here is my PendingIntent:

  Intent i = new Intent(mContext, AlarmReceiver.class);  
  PendingIntent pi = PendingIntent.getBroadcast(G.context, _id, i,
                 PendingIntent.FLAG_UPDATE_CURRENT);

Which each _id is unique and when I make a receiver for date changed event before my alarm cancel method fired previous alarms go off!

Can some body help to solve this problem?

Gustavo Morales
  • 2,614
  • 9
  • 29
  • 37

3 Answers3

0

Try this code:

Intent intent = new Intent(this, Mote.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 1253, intent, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.cancel(pendingIntent);

0

For cancel the alarm:

 Intent intent = new Intent(this, Mote.class);
 PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 1253, intent, 0);
 AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
 alarmManager.cancel(pendingIntent);

Edit

Well you can look for the answer and modify as per your requirements:

How to stop Android AlarmManager when there is a manual system time change?

AlarmManager: how to schedule a daily alarm and deal with time changes

Community
  • 1
  • 1
Android Geek
  • 8,956
  • 2
  • 21
  • 35
0
 Intent intent1 = new Intent(G.context, DailyAlarmReceiver.class);
 PendingIntent pendingIntent = PendingIntent.getBroadcast(G.context,
     G.dateTimesetAlarm.getDayOfYear(), intent1, 0);
 mAlarmManager.cancel(pendingIntent);
 pendingIntent.cancel();
Laurel
  • 5,965
  • 14
  • 31
  • 57