当前位置: 首页>>代码示例>>Java>>正文


Java AlarmManager.setExactAndAllowWhileIdle方法代码示例

本文整理汇总了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);
        }
    }
}
 
开发者ID:ruuvi,项目名称:com.ruuvi.station,代码行数:20,代码来源:BackgroundScanner.java

示例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, "提醒设置成功");
}
 
开发者ID:StableChen,项目名称:easynote,代码行数:16,代码来源:SetNotificationActivity.java

示例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);
}
 
开发者ID:MBach,项目名称:AutoAirplaneMode,代码行数:27,代码来源:AlarmBroadcastReceiver.java

示例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) + ")");

}
 
开发者ID:jcolladosp,项目名称:ePills,代码行数:46,代码来源:AlarmUtil.java

示例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);
    }
}
 
开发者ID:adithya321,项目名称:SOS-The-Healthcare-Companion,代码行数:14,代码来源:AlarmUtil.java

示例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);
        }
    }
 
开发者ID:zhuyu1022,项目名称:amap,代码行数:17,代码来源:MapAlarmCheckService.java

示例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);
    }
}
 
开发者ID:monthlypub,项目名称:SmingZZick_App,代码行数:14,代码来源:AttackManager.java

示例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);
}
 
开发者ID:androidthings,项目名称:sample-updatemanager,代码行数:14,代码来源:UpdateActivity.java

示例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);

    }
}
 
开发者ID:seeing-eye,项目名称:UnforgetIt,代码行数:35,代码来源:AlarmReceiver.java

示例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);
    }
}
 
开发者ID:BolexLiu,项目名称:TimeTask,代码行数:16,代码来源:TimeTask.java

示例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));

}
 
开发者ID:OldBigBuddha,项目名称:AlarmWithL-T,代码行数:6,代码来源:SettingFragment.java


注:本文中的android.app.AlarmManager.setExactAndAllowWhileIdle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。