本文整理汇总了Java中android.app.AlarmManager.setExactAndAllowWhileIdle方法的典型用法代码示例。如果您正苦于以下问题:Java AlarmManager.setExactAndAllowWhileIdle方法的具体用法?Java AlarmManager.setExactAndAllowWhileIdle怎么用?Java AlarmManager.setExactAndAllowWhileIdle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.AlarmManager
的用法示例。
在下文中一共展示了AlarmManager.setExactAndAllowWhileIdle方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scheduleNextScan
import android.app.AlarmManager; //导入方法依赖的package包/类
private void scheduleNextScan(Context context) {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
int scanInterval = Integer.parseInt(settings.getString("pref_scaninterval", "300")) * 1000;
if (scanInterval < 15 * 1000) scanInterval = 15 * 1000;
boolean batterySaving = settings.getBoolean("pref_bgscan_battery_saving", false);
Intent intent = new Intent(context, BackgroundScanner.class);
PendingIntent sender = PendingIntent.getBroadcast(context, BackgroundScanner.REQUEST_CODE, intent, 0);
AlarmManager am = (AlarmManager) context
.getSystemService(ALARM_SERVICE);
if (!batterySaving) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
am.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + scanInterval, sender);
}
else {
am.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + scanInterval, sender);
}
}
}
示例2: setNotification
import android.app.AlarmManager; //导入方法依赖的package包/类
private void setNotification(long time) {
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent("whut.dongdong.easynote.NOTIFY_BROADCAST");
intent.putExtra("noteId", noteId);
PendingIntent pendingIntent = PendingIntent
.getBroadcast(this, noteId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
manager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, time, pendingIntent);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
manager.setExact(AlarmManager.RTC_WAKEUP, time, pendingIntent);
} else {
manager.set(AlarmManager.RTC_WAKEUP, time, pendingIntent);
}
ToastUtil.showToast(this, "提醒设置成功");
}
示例3: setAlarmEnableAirplaneMode
import android.app.AlarmManager; //导入方法依赖的package包/类
public void setAlarmEnableAirplaneMode(Context context)
{
Log.d(TAG, "setAlarmEnableAirplaneMode");
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
String enableAutoAirplaneMode = settings.getString(Constants.ENABLE_AIRPLANE_TIME, "23:00");
String[] enable = enableAutoAirplaneMode.split(":");
Calendar now = Calendar.getInstance();
Calendar calendarStart = Calendar.getInstance();
now.setTimeInMillis(System.currentTimeMillis());
calendarStart.setTimeInMillis(now.getTimeInMillis());
calendarStart.set(Calendar.HOUR_OF_DAY, Integer.valueOf(enable[0]));
calendarStart.set(Calendar.MINUTE, Integer.valueOf(enable[1]));
calendarStart.set(Calendar.SECOND, 0);
calendarStart.set(Calendar.MILLISECOND, 0);
Intent intentEnable = new Intent(context, AlarmBroadcastReceiver.class);
intentEnable.putExtra(Constants.ID, Constants.ID_ENABLE);
enableAirplaneModePendingIntent = PendingIntent.getBroadcast(context, Constants.ID_ENABLE, intentEnable, 0);
alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, calendarStart.getTimeInMillis(), enableAirplaneModePendingIntent);
setAlarmAfterReboot(context, true);
}
示例4: setAlarm
import android.app.AlarmManager; //导入方法依赖的package包/类
static public void setAlarm(Context context, String medicineName, int quantity, Date startDate, Date endDate, int alarmId, boolean isEnable) {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent;
Intent intent = new Intent(context, AlarmBroadcastReceiver.class);
intent.putExtra("startDate", startDate.getTime());
intent.putExtra("endDate", endDate.getTime());
intent.putExtra("medicineName", medicineName);
intent.putExtra("alarmId", alarmId);
intent.putExtra("quantity", quantity);
if(startDate.compareTo(endDate) == 0){ //same date
intent.putExtra("isOnce", 1);
}
else{
intent.putExtra("isOnce", 0);
}
if(isEnable){
intent.putExtra("isEnable", true);
}
else{
intent.putExtra("isEnable", false);
}
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.setTime(startDate);
pendingIntent = PendingIntent.getBroadcast(context, alarmId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
//Compatibility check
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP,
calendar.getTimeInMillis(),
pendingIntent);
}
else{
alarmManager.setExact(alarmManager.RTC_WAKEUP,
calendar.getTimeInMillis(),
pendingIntent);
}
Log.e("set alarm:", String.valueOf(calendar.getTime()) + " (" + String.valueOf(alarmId) + ")");
}
示例5: setAlarm
import android.app.AlarmManager; //导入方法依赖的package包/类
public static void setAlarm(Context context, Intent intent, int notificationId, Calendar calendar) {
intent.putExtra("NOTIFICATION_ID", notificationId);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
} else {
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
}
}
示例6: startAlarmService
import android.app.AlarmManager; //导入方法依赖的package包/类
/**
* 通过Alarm的方式启动服务
// */
private void startAlarmService() {
long second = 5 * 60 * 1000;
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
long traggerAtTime = SystemClock.elapsedRealtime() + second;
Intent i = new Intent(MapAlarmCheckService.this, MapAlarmCheckService.class);
pendingIntent = PendingIntent.getService(MapAlarmCheckService.this, 0, i, 0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, traggerAtTime, pendingIntent);
}else {
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, traggerAtTime, pendingIntent);
}
}
示例7: registAlarm
import android.app.AlarmManager; //导入方法依赖的package包/类
private void registAlarm(AlarmManager alarmManager, long triggerAtMills, PendingIntent pendingIntent) {
if (System.currentTimeMillis() > triggerAtMills) {
return;
}
if (Build.VERSION.SDK_INT >= 23) {
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerAtMills, pendingIntent);
} else if (Build.VERSION.SDK_INT >= 19) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, triggerAtMills, pendingIntent);
} else {
alarmManager.set(AlarmManager.RTC_WAKEUP, triggerAtMills, pendingIntent);
}
}
示例8: scheduleReboot
import android.app.AlarmManager; //导入方法依赖的package包/类
/**
* Schedule a device reboot at the specified time.
*
* @param time wallclock time in milliseconds since epoch.
*/
private void scheduleReboot(long time) {
Intent intent = DeviceRebootReceiver.getRestartIntent(this);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent,
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, time, pendingIntent);
}
示例9: setAlarm
import android.app.AlarmManager; //导入方法依赖的package包/类
public void setAlarm(Context context, Task task) {
boolean isActive = !task.isDone() &&
task.getAlarmAdvanceTime() != 0 &&
new Date(task.getDate().getTime() + task.getAlarmAdvanceTime()).after(new Date());
if (isActive) {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmReceiver.class);
intent.putExtra(TITLE, task.getTitle());
intent.putExtra(ID, task.getId().intValue());
intent.putExtra(ALARM_ADVANCE_TIME, task.getAlarmAdvanceTime());
intent.putExtra(DATE, task.getDate().getTime());
intent.putExtra(PRIORITY, task.getPriorityLevel());
Log.d(this.getClass().getName(), "Init " + task.getAlarmAdvanceTime() + "ms alarm for " + task);
PendingIntent alarmIntent = PendingIntent.getBroadcast(context, task.getId().intValue(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, task.getDate().getTime() - task.getAlarmAdvanceTime(), alarmIntent);
} else {
alarmManager.set(AlarmManager.RTC_WAKEUP, task.getDate().getTime() - task.getAlarmAdvanceTime(), alarmIntent);
}
intentMap.put(task.getId().intValue(), alarmIntent);
ComponentName receiver = new ComponentName(context, AlarmReceiver.class);
PackageManager pm = context.getPackageManager();
pm.setComponentEnabledSetting(receiver,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
}
}
示例10: configureAlarmManager
import android.app.AlarmManager; //导入方法依赖的package包/类
/**
* 装在定时任务
* @param Time
*/
private void configureAlarmManager(long Time) {
AlarmManager manager = (AlarmManager) mContext.getSystemService(ALARM_SERVICE);
PendingIntent pendIntent = getPendingIntent();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
manager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, Time, pendIntent);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
manager.setExact(AlarmManager.RTC_WAKEUP, Time, pendIntent);
} else {
manager.set(AlarmManager.RTC_WAKEUP, Time, pendIntent);
}
}
示例11: setExactAndAllowWhileIdle
import android.app.AlarmManager; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
private void setExactAndAllowWhileIdle(AlarmManager manager) {
manager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, mSchedule.getTimeInMillis(), settingAlarm(mData));
}