本文整理汇总了Java中android.app.AlarmManager.ELAPSED_REALTIME_WAKEUP属性的典型用法代码示例。如果您正苦于以下问题:Java AlarmManager.ELAPSED_REALTIME_WAKEUP属性的具体用法?Java AlarmManager.ELAPSED_REALTIME_WAKEUP怎么用?Java AlarmManager.ELAPSED_REALTIME_WAKEUP使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.app.AlarmManager
的用法示例。
在下文中一共展示了AlarmManager.ELAPSED_REALTIME_WAKEUP属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: restartApplication
/**
* 重启App
*
* @param context application
* @param delay 当前App被杀死之后,延迟多久重新启动。
*/
public static void restartApplication(Context context, int delay) {
Intent intent = context.getPackageManager()
.getLaunchIntentForPackage(context.getPackageName());
PendingIntent restartIntent = PendingIntent.getActivity(context.getApplicationContext(), 0
, intent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
int type = AlarmManager.ELAPSED_REALTIME_WAKEUP;
long triggerTime = SystemClock.elapsedRealtime() + delay;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mgr.setExact(type, triggerTime, restartIntent);
} else {
mgr.set(type, triggerTime, restartIntent);
}
Process.killProcess(Process.myPid());
}
示例2: doSchedule
private synchronized int doSchedule(int entryId, int intervalMs) {
//Log.d(THIS_FILE, "SCHED add " + entryId + " in " + intervalMs);
long firstTime = SystemClock.elapsedRealtime();
// Clamp min
if(intervalMs < 10) {
firstTime += 10;
}else {
firstTime += intervalMs;
}
PendingIntent pendingIntent = getPendingIntentForTimer(entryId, firstTime);
// If less than 1 sec, do not wake up -- that's probably stun check so useless to wake up about that
//int alarmType = (intervalMs < 1000) ? AlarmManager.ELAPSED_REALTIME : AlarmManager.ELAPSED_REALTIME_WAKEUP;
int alarmType = AlarmManager.ELAPSED_REALTIME_WAKEUP;
// Cancel previous reg anyway
alarmManager.cancel(pendingIntent);
int existingReg = scheduleEntries.indexOf((Integer) entryId);
if(existingReg != -1) {
scheduleEntries.remove(existingReg);
scheduleTimes.remove(existingReg);
}
// Push next
Log.v(THIS_FILE, "Schedule timer " + entryId + " in " + intervalMs + "ms @ " + firstTime);
Compatibility.setExactAlarm(alarmManager, alarmType, firstTime, pendingIntent);
scheduleEntries.add((Integer) entryId);
scheduleTimes.add((Long) firstTime);
return 1;
}
示例3: scheduleSystemAlarm
private void scheduleSystemAlarm() {
alarmPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, SummaryActivity.class), PendingIntent.FLAG_CANCEL_CURRENT);
int type = AlarmManager.ELAPSED_REALTIME_WAKEUP;
long trigger = SystemClock.elapsedRealtime() + COUNTDOWN_DURATION;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
alarmManager.setExactAndAllowWhileIdle(type, trigger, alarmPendingIntent);
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
alarmManager.setExact(type, trigger, alarmPendingIntent);
else
alarmManager.set(type, trigger, alarmPendingIntent);
}