use of android.app.AlarmManager in project AlarmAndJob by dxsdyhm.
the class TostServiceHelper method initAlarmmager.
public static void initAlarmmager(Context context) {
// 操作:发送一个广播,广播接收后Toast提示定时操作完成
Intent intent = new Intent(context, AlarmRecive.class);
intent.setAction("tost");
PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
// 开始时间
long firstime = SystemClock.elapsedRealtime();
AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
// 或者以下面方式简化
alarm.setRepeating(AlarmManager.RTC_WAKEUP, firstime, SCEDULE_TIME, sender);
}
use of android.app.AlarmManager in project orgzly-android by orgzly.
the class ListWidgetProvider method scheduleUpdate.
private static void scheduleUpdate(Context context) {
/*
schedule updates via AlarmManager, because we don't want to wake the device on every update
see https://developer.android.com/guide/topics/appwidgets/index.html#MetaData
*/
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
PendingIntent intent = getAlarmIntent(context);
alarmManager.cancel(intent);
/* repeat after every full hour because results of search can change on new day
because of timezones repeat every hour instead of every day */
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.HOUR_OF_DAY, 1);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 1);
alarmManager.setInexactRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), AlarmManager.INTERVAL_HOUR, intent);
}
use of android.app.AlarmManager in project AndroidChromium by JackyAndroid.
the class ExponentialBackoffScheduler method createAlarm.
/**
* Creates an alarm to fire the specified intent at the specified time.
* @param intent The intent to fire.
* @return the timestamp of the scheduled intent
*/
public long createAlarm(Intent intent, long timestamp) {
PendingIntent retryPIntent = PendingIntent.getService(mContext, 0, intent, 0);
AlarmManager am = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
setAlarm(am, timestamp, retryPIntent);
return timestamp;
}
use of android.app.AlarmManager in project AndroidChromium by JackyAndroid.
the class OmahaClient method cancelRepeatingAlarm.
/**
* Cancels the alarm that launches this service. It will be replaced when Chrome next resumes.
*/
private void cancelRepeatingAlarm() {
Intent requestIntent = createRegisterRequestIntent(this);
PendingIntent pendingIntent = PendingIntent.getService(this, 0, requestIntent, PendingIntent.FLAG_NO_CREATE);
// If the pendingIntent is null, it is likely that no alarm was created.
if (pendingIntent != null) {
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
am.cancel(pendingIntent);
pendingIntent.cancel();
}
}
use of android.app.AlarmManager in project AndroidChromium by JackyAndroid.
the class OmahaClient method scheduleRepeatingAlarm.
/**
* Sets a repeating alarm that fires request registration Intents.
* Setting the alarm overwrites whatever alarm is already there, and rebooting
* clears whatever alarms are currently set.
*/
private void scheduleRepeatingAlarm() {
Intent registerIntent = createRegisterRequestIntent(this);
PendingIntent pIntent = PendingIntent.getService(this, 0, registerIntent, 0);
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
setAlarm(am, pIntent, AlarmManager.RTC, mTimestampForNewRequest);
}
Aggregations