set Alarm Interval Time for PollingService - Android android.app

Android examples for android.app:Alarm Set up

Description

set Alarm Interval Time for PollingService

Demo Code

import com.android.push.service.PollingService;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;

public class Main {

  private static void setAlarmIntervalTime(Context context, long intervalTime) {
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    Intent intent = new Intent(context, PollingService.class);
    PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    am.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + intervalTime, pendingIntent);
  }/*from w ww.j  ava2  s .com*/

}

Related Tutorials