本文整理匯總了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);
}