use of android.app.AlarmManager in project android_packages_apps_OmniClock by omnirom.
the class TimerReceiver method updateNextTimesup.
// Scan all timers and find the one that will expire next.
// Tell AlarmManager to send a "Time's up" message to this receiver when this timer expires.
// If no timer exists, clear "time's up" message.
private void updateNextTimesup(Context context) {
TimerObj t = getNextRunningTimer(mTimers, false, Utils.getTimeNow());
long nextTimesup = (t == null) ? -1 : t.getTimesupTime();
int timerId = (t == null) ? -1 : t.mTimerId;
Intent intent = new Intent();
intent.setAction(Timers.TIMES_UP);
intent.setClass(context, TimerReceiver.class);
if (!mTimers.isEmpty()) {
intent.putExtra(Timers.TIMER_INTENT_EXTRA, timerId);
}
AlarmManager mngr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
PendingIntent p = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);
if (t != null) {
mngr.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextTimesup, p);
if (Timers.LOGGING) {
Log.d(TAG, "Setting times up to " + nextTimesup);
}
} else {
mngr.cancel(p);
if (Timers.LOGGING) {
Log.v(TAG, "no next times up");
}
}
}
use of android.app.AlarmManager in project android_packages_apps_OmniClock by omnirom.
the class Utils method getNextAlarm.
/**
* @return The next alarm from {@link AlarmManager}
*/
public static String getNextAlarm(Context context) {
String timeString = null;
final AlarmManager.AlarmClockInfo info = ((AlarmManager) context.getSystemService(Context.ALARM_SERVICE)).getNextAlarmClock();
if (info != null) {
final long triggerTime = info.getTriggerTime();
final Calendar alarmTime = Calendar.getInstance();
alarmTime.setTimeInMillis(triggerTime);
timeString = AlarmUtils.getFormattedTime(context, alarmTime);
}
return timeString;
}
use of android.app.AlarmManager in project android_packages_apps_OmniClock by omnirom.
the class AlarmNotifications method registerNextAlarmWithAlarmManager.
public static void registerNextAlarmWithAlarmManager(Context context, AlarmInstance instance) {
// Sets a surrogate alarm with alarm manager that provides the AlarmClockInfo for the
// alarm that is going to fire next. The operation is constructed such that it is ignored
// by AlarmStateManager.
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
int flags = instance == null ? PendingIntent.FLAG_NO_CREATE : 0;
PendingIntent operation = PendingIntent.getBroadcast(context, 0, /* requestCode */
AlarmStateManager.createIndicatorIntent(context), flags);
if (instance != null) {
long alarmTime = instance.getAlarmTime().getTimeInMillis();
// Create an intent that can be used to show or edit details of the next alarm.
PendingIntent viewIntent = PendingIntent.getActivity(context, instance.hashCode(), createViewAlarmIntent(context, instance), PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager.AlarmClockInfo info = new AlarmManager.AlarmClockInfo(alarmTime, viewIntent);
alarmManager.setAlarmClock(info, operation);
} else if (operation != null) {
alarmManager.cancel(operation);
}
}
use of android.app.AlarmManager in project android_packages_apps_OmniClock by omnirom.
the class AlarmStateManager method cancelScheduledInstance.
/**
* Cancel all {@link AlarmManager} timers for instance.
*
* @param context application context
* @param instance to disable all {@link AlarmManager} timers
*/
private static void cancelScheduledInstance(Context context, AlarmInstance instance) {
LogUtils.v("Canceling instance " + instance.mId + " timers");
// Create a PendingIntent that will match any one set for this instance
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, instance.hashCode(), createStateChangeIntent(context, ALARM_MANAGER_TAG, instance, null), PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.cancel(pendingIntent);
}
use of android.app.AlarmManager in project AmazeFileManager by TeamAmaze.
the class FTPService method onTaskRemoved.
// Restart the service if the app is closed from the recent list
@Override
public void onTaskRemoved(Intent rootIntent) {
super.onTaskRemoved(rootIntent);
Intent restartService = new Intent(getApplicationContext(), this.getClass());
restartService.setPackage(getPackageName());
PendingIntent restartServicePI = PendingIntent.getService(getApplicationContext(), 1, restartService, PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmService = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
alarmService.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 2000, restartServicePI);
}
Aggregations