List of usage examples for android.app PendingIntent getService
public static PendingIntent getService(Context context, int requestCode, @NonNull Intent intent, @Flags int flags)
From source file:Main.java
public static final void Alarm_service(Context ctx, long atTime, Class<?> cls) { ((AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE)).set(AlarmManager.RTC_WAKEUP, atTime, PendingIntent.getService(ctx, 0, new Intent(ctx, cls), 0)); }
From source file:Main.java
public static void stopServiceAlarm(Context context, Class<?> service) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(context, service); PendingIntent p = PendingIntent.getService(context, 10000, i, PendingIntent.FLAG_CANCEL_CURRENT); am.cancel(p);//from w w w. j a v a 2s. c om }
From source file:Main.java
public static void startServiceAlarm(Context context, Class<?> service, long interval) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(context, service); PendingIntent p = PendingIntent.getService(context, 10000, i, PendingIntent.FLAG_CANCEL_CURRENT); am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, 0, interval, p); }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.CUPCAKE) public static void startAlarmService(Context context, int triggerAtMillis, Class<?> cls, String action) { Intent intent = new Intent(context, cls); intent.setAction(action);/*from www . j a v a 2 s . com*/ PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); startAlarmIntent(context, triggerAtMillis, pendingIntent); }
From source file:Main.java
public static void closeService(Context context, Class<?> cls, String action) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, cls); intent.setAction(action);/* w w w . j a va 2 s. c o m*/ PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.cancel(pendingIntent); }
From source file:Main.java
public static final void BindClickAction(final Context context, final RemoteViews views, final int resId, final int widgetId, final Intent intent) { final int requestCode = generateRequestCode(resId, widgetId); PendingIntent pIntent = PendingIntent.getService(context, requestCode, intent, PENDING_INTENT_FLAGS); views.setOnClickPendingIntent(resId, pIntent); }
From source file:Main.java
public static synchronized boolean isServiceAlarmOn(Context context, Intent intent, int identifier) { PendingIntent pi = PendingIntent.getService(context, identifier, intent, PendingIntent.FLAG_NO_CREATE); return pi != null; }
From source file:Main.java
public static synchronized void cancelServiceAlarm(Context context, Intent intent, int identifier) { final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final PendingIntent pi = PendingIntent.getService(context, identifier, intent, PendingIntent.FLAG_NO_CREATE); if (pi != null) { am.cancel(pi);//ww w . j a v a2 s .c o m pi.cancel(); } }
From source file:Main.java
public static synchronized long setServiceAlarm(Context context, Intent intent, long timeInterval, int identifier) { final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final PendingIntent pi = PendingIntent.getService(context, identifier, intent, PendingIntent.FLAG_CANCEL_CURRENT); return setUpAlarm(am, pi, timeInterval); }
From source file:com.meiste.greg.ptw.RaceAlarm.java
@SuppressLint("NewApi") public static void set(final Context context) { final Race race = Race.getNext(context, true, true); if (!alarm_set && (race != null)) { Util.log("Setting race alarm for race " + race.getId()); final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final Intent intent = new Intent(context, RaceAlarm.class); intent.putExtra(RACE_ID, race.getId()); final PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { am.setExact(AlarmManager.RTC_WAKEUP, race.getStartTimestamp(), pendingIntent); } else {//from w w w. ja v a 2 s .c o m am.set(AlarmManager.RTC_WAKEUP, race.getStartTimestamp(), pendingIntent); } alarm_set = true; } else { Util.log("Not setting race alarm: alarm_set=" + alarm_set); } }