-4

How can we set an AlarmManager, for a ContentObserver class in PendingIntent?

Possible methods are :

  PendingIntent.getActivity

  PendingIntent.getService

  PendingIntent.getBroadCast

So, which one to use if it is at all possible?

Rudi Visser
  • 21,350
  • 5
  • 71
  • 97
Nikita
  • 189
  • 1
  • 4
  • 16

1 Answers1

0

PendingIntent.getBroadCast is the right ans for the question you have. you can use as below

Intent alarm_intent = new Intent(getApplicationContext(),
                AlarmReceiver.class);
        // In reality, you would want to have a static variable for the request
        // code instead of 192837
        PendingIntent sender = PendingIntent.getBroadcast(this, 192837,
                alarm_intent, PendingIntent.FLAG_UPDATE_CURRENT);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        calendar.add(Calendar.MINUTE, 15);
        long interval = 900 * 1000; //
        // Get the AlarmManager service
        AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
        am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
                interval, sender);
Dinesh Prajapati
  • 9,274
  • 5
  • 30
  • 47