List of usage examples for android.app AlarmManager set
public void set(@AlarmType int type, long triggerAtMillis, PendingIntent operation)
Schedule an alarm.
From source file:Main.java
private static void setAlarmBefore19(AlarmManager am, long timestamp, PendingIntent pendingIntent) { am.set(AlarmManager.RTC_WAKEUP, timestamp, pendingIntent); }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.CUPCAKE) public static void startAlarmIntent(Context context, int triggerAtMillis, PendingIntent pendingIntent) { AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); manager.set(AlarmManager.RTC_WAKEUP, triggerAtMillis, pendingIntent); }
From source file:Main.java
public static void exitAndRestart(Context context, Class<?> activityCls) { Intent intent = new Intent(context, activityCls); PendingIntent restartIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); mgr.set(1, System.currentTimeMillis() + 1000L, restartIntent); }
From source file:Main.java
public static void setAlarm(Context context, PendingIntent intent, long time) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.set(AlarmManager.RTC_WAKEUP, time, intent); }
From source file:Main.java
/** * Restart the app./* w w w . j a v a2 s. c om*/ * @param context */ public static void restartApplication(Context context) { Intent i = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent p = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 500, p); //kill the application System.exit(0); }
From source file:Main.java
public static PendingIntent scheduleLocalNotification(Context context, int slot, Long alertTime, String titleText, String subtitleText, String messageBodyText, String tickerText) { Log.i(TAG, "Scheduling local notification"); Intent alertIntent = new Intent(getNotificationName(slot)); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, slot, alertIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (alarmManager != null) { alarmManager.set(AlarmManager.RTC_WAKEUP, alertTime, pendingIntent); }/*w w w.ja v a 2 s . co m*/ return pendingIntent; }
From source file:Main.java
public static PendingIntent scheduleLocalNotification(Context context, int slot, String title, String message, Long alertTime, int repeat) { Log.i(TAG, "Scheduling local notification"); Intent alertIntent = new Intent(getNotificationName(slot)); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, slot, alertIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (alarmManager != null) { if (repeat == 0) { alarmManager.set(AlarmManager.RTC_WAKEUP, alertTime, pendingIntent); } else {//from w w w .jav a 2 s. c om Calendar alarmStartTime = Calendar.getInstance(); alarmStartTime.add(Calendar.MINUTE, 1); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, alertTime, repeat, pendingIntent); } } return pendingIntent; }
From source file:cat.wuyingren.whatsannoy.utils.SystemUtils.java
public static void createAlarm(Context context, Schedule schedule) { Log.w("UTILS", "createAlarm() / Scheduled: " + schedule.getId()); Intent alarmIntent = new Intent(context, Alarm.class); alarmIntent.putExtra(Alarm.PREF_ALARM_ID, schedule.getId()); PendingIntent pi = PendingIntent.getBroadcast(context, SystemUtils.safeLongToInt(schedule.getId()), alarmIntent, 0);/*from www .j a va 2 s . c o m*/ AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmMgr.set(AlarmManager.RTC_WAKEUP, schedule.getDate(), pi); }
From source file:cat.wuyingren.whatsannoy.utils.SystemUtils.java
public static long createAlarm(Context context, int frequency, int alarmID) { Log.w("UTILS", "createAlarm()"); Intent alarmIntent = new Intent(context, Alarm.class); alarmIntent.putExtra(Alarm.PREF_ALARM_ID, alarmID); PendingIntent pi = PendingIntent.getBroadcast(context, -1, alarmIntent, 0); Random r = new Random(); int addMin = r.nextInt(frequency); if (addMin < 1) { addMin = 1;//from ww w . jav a 2 s . c om } Calendar c = Calendar.getInstance(); c.add(Calendar.MINUTE, addMin); c.add(Calendar.SECOND, 0); AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmMgr.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), pi); return c.getTimeInMillis(); }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.KITKAT) public static void setAlarmExact(Context context, int type, long triggerAtMillis, PendingIntent pendingIntent) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { alarmManager.setExact(type, triggerAtMillis, pendingIntent); } else {//from w ww .j av a 2s . c om alarmManager.set(type, triggerAtMillis, pendingIntent); } }