-1

I want to run some task in background without telling user, to send some data to server.

Requirement is, after every fifteen minutes I have to send some data. So need Alarm Triggered after every 15 Min.

I am using AlarmManager but not achieving.

Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY,5);
cal.set(Calendar.MINUTE,10);//
cal.set(Calendar.SECOND, 0);
Intent intent = new Intent(this, TaskReceiver.class);
pintent = PendingIntent.getService(this, 0, intent, 0);
alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
long repeatingTime = 2 * 60 * 1000;

alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),repeatingTime, pintent);
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
Devendra Singh
  • 2,343
  • 4
  • 26
  • 47

1 Answers1

0

done using this:

public static void registerAlarm(Context context) {
  Intent i = new Intent(context, TaskReceiver.class);

  PendingIntent sender = PendingIntent.getBroadcast(context, 147, i, 0);

  // We want the alarm to go off 3 seconds from now.
  long firstTime = SystemClock.elapsedRealtime();
  firstTime += 3 * 1000;//start 3 seconds after first register.

  // Schedule the alarm!
  AlarmManager am = (AlarmManager) context.getSystemService(ALARM_SERVICE);
  am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime,
            600000, sender);//10min interval
}
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
Devendra Singh
  • 2,343
  • 4
  • 26
  • 47