Java 类android.app.AlarmManager 实例源码

项目:PeSanKita-android    文件:ExpirationListener.java   
public static void setAlarm(Context context, long waitTimeMillis) {
  Intent        intent        = new Intent(context, ExpirationListener.class);
  PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
  AlarmManager  alarmManager  = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);

  alarmManager.cancel(pendingIntent);
  alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + waitTimeMillis, pendingIntent);
}
项目:CouponsTracker    文件:AppWidgetAlarmManager.java   
/**
 * Sets a daily recurring alarm that is to trigger that
 * 2 am device time.
 */
public static void setAlarm(Context context) {
    DebugLog.logMethod();
    context.getApplicationContext();

    PendingIntent pendingIntent = getPendingIntent(context);
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 2);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.setInexactRepeating(
            AlarmManager.RTC_WAKEUP,
            calendar.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY,
            pendingIntent
    );
}
项目:1946    文件:GcmPush.java   
public void pushLocalNotification( float fireTimeOffsetS, String title, String message, String data )
{
    //Log.i("yoyo", "local notifcation scheduled in " + fireTimeOffsetS + " seconds");
    Context appContext = mContext.getApplicationContext();
    Intent intent = new Intent( appContext, PushLocalAlarmReceiver.class);
    intent.putExtra( KEY_NTF_TITLE, title );
    intent.putExtra( KEY_NTF_MESSAGE, message );
    intent.putExtra( KEY_NTF_DATA, data);

    //problems stacking multiple alarms...try this??
    long timeMilli = System.currentTimeMillis() + (long)(fireTimeOffsetS*1000);
    int uniqueID = (int)timeMilli;
    PendingIntent pendingIntent = PendingIntent.getBroadcast(appContext, uniqueID, intent, PendingIntent.FLAG_ONE_SHOT);
    AlarmManager am = (AlarmManager)appContext.getSystemService(Context.ALARM_SERVICE);

    am.set(AlarmManager.RTC_WAKEUP, timeMilli, pendingIntent);

    //store details of alarm - so it can be cancelled
    storePendingLocalAlarm( title, message, data, timeMilli );

}
项目:iosched-reader    文件:SyncCommand.java   
private void scheduleSync(Context context, int syncJitter) {
    int jitterMillis = (int) (RANDOM.nextFloat() * syncJitter);
    final String debugMessage = "Scheduling next sync for " + jitterMillis + "ms";
    LOGI(TAG, debugMessage);

    ((AlarmManager) context.getSystemService(Context.ALARM_SERVICE))
            .set(
                    AlarmManager.RTC,
                    System.currentTimeMillis() + jitterMillis,
                    PendingIntent.getBroadcast(
                            context,
                            0,
                            new Intent(context, TriggerSyncReceiver.class),
                            PendingIntent.FLAG_CANCEL_CURRENT));

}
项目:DoList    文件:EditActivity.java   
public void setclickalarm(int id) {

        int requestCode = 0;

        requestCode = idValue;
        // ---------------------------------------------------------------------
        AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
        Intent intent = new Intent(List.alist, ClockActivity.class);
        intent.putExtra("content", contentValue);// ��������
        intent.putExtra("alarmtime", alarmValue);// ��������ʱ��
        PendingIntent pi = PendingIntent.getActivity(List.alist, requestCode,
                intent, PendingIntent.FLAG_CANCEL_CURRENT); // ����id���ò�ͬ������
        Calendar alarmTime = Calendar.getInstance();
        long alarmdatetime = changedatetime(alarmValue); // ��ʱ��ת��Ϊlong��
        alarmManager.set(AlarmManager.RTC_WAKEUP, alarmdatetime, pi);
        Toast.makeText(getApplicationContext(), "�������ú���", Toast.LENGTH_LONG)
                .show();
    }
项目:FreshMember    文件:DaemonStrategyUnder21.java   
private void initAlarm(Context context, String serviceName){
    if(mAlarmManager == null){
           mAlarmManager = ((AlarmManager)context.getSystemService(Context.ALARM_SERVICE));
       }
       if(mPendingIntent == null){
           Intent intent = new Intent();
        ComponentName component = new ComponentName(context.getPackageName(), serviceName);
        intent.setComponent(component);
           intent.setFlags(Intent.FLAG_EXCLUDE_STOPPED_PACKAGES);
           mPendingIntent = PendingIntent.getService(context, 0, intent, 0);
       }
       mAlarmManager.cancel(mPendingIntent);
}
项目:Shush    文件:AlarmScheduler.java   
/**
 * Set an alarm to silence the phone.
 *
 * @param startTimeInMillis The time at which phone is to be shushed
 * @param endTimeInMillis   The time at which phone is to be un-shushed
 */
public void setAlarm(long startTimeInMillis, long endTimeInMillis) {
    if (startTimeInMillis >= endTimeInMillis) {
        return;
    }
    alarmManager.set(
            AlarmManager.RTC_WAKEUP,
            startTimeInMillis,
            getDefaultPendingIntent(true)
    );
    alarmManager.set(
            AlarmManager.RTC_WAKEUP,
            endTimeInMillis,
            getDefaultPendingIntent(false)
    );
}
项目:Lazy-Switches    文件:BluetoothActivity.java   
private void setAlarm(Calendar targetCal) {
//        Calendar calNow = ;
        long timeInMilis = targetCal.getTimeInMillis() - Calendar.getInstance().getTimeInMillis();
        long seconds = timeInMilis / 1000;
        long minutes = seconds / 60;
        long hours = minutes / 60;
        String time = hours % 24 + " hours," + minutes % 60 + " minutes," + seconds % 60 + " seconds";


        Toast.makeText(getApplicationContext(), "Alarm set to " + (time) + " from now", Toast.LENGTH_LONG).show();

        Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
        intent.putExtra(Constants.EXTRA_DEVICE, device);
        intent.putExtra(Constants.STATE_DEVICE, buttons_state);
//        Log.d("mmeessaaggee","buttons alarm state  "+buttons_state);
        AppUtils.saveAlarmState(getApplicationContext(), Constant.BUTTON_ALARM_STATE, buttons_state);

        PendingIntent pendingIntent = PendingIntent.getBroadcast(
                getBaseContext(), RQS_1, intent, 0);
        AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(),
                pendingIntent);

    }
项目:orgzly-android    文件:ListWidgetProvider.java   
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);
}
项目:Weather365    文件:AutoUpdateService.java   
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    updateWeather();
    updateBingPic();
    AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE);
    int anHour = 4 * 60 * 60 * 1000;//4个小时的毫秒数
    long triggerAtTime = SystemClock.elapsedRealtime() + anHour;
    Intent i = new Intent(this, AutoUpdateService.class);
    PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
    manager.cancel(pi);
    manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, pi);
    return super.onStartCommand(intent, flags, startId);
}
项目:Android-DownloadManager    文件:DownloadService.java   
/**
 * Initializes the service when it is first created
 */
@Override
public void onCreate() {
    super.onCreate();
    if (Constants.LOGVV) {
        Log.v(Constants.TAG, "Service onCreate");
    }

    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    mUpdateThread = new HandlerThread(TAG + "-UpdateThread");
    mUpdateThread.start();
    mUpdateHandler = new Handler(mUpdateThread.getLooper(), mUpdateCallback);

    mNotifier = new DownloadNotifier(this);
    mNotifier.cancelAll();

    mObserver = new DownloadManagerContentObserver();
    getContentResolver().registerContentObserver(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI,
            true, mObserver);

}
项目:Botanist    文件:DatabaseManager.java   
/**
 * Delete the all reminders
 * @param context - the current app context
 */
public void deleteAllReminders(Context context) {
    AlarmManager am = (AlarmManager) context.getSystemService(ALARM_SERVICE);
    for (int i = 0; i < mPlantsNumber; i++) {
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, i, new Intent(context, BirthdayReceiver.class), 0);
        if (am != null) {
            am.cancel(pendingIntent);
            pendingIntent = PendingIntent.getBroadcast(context, i, new Intent(context, FertilizerReceiver.class), 0);
            am.cancel(pendingIntent);
            pendingIntent = PendingIntent.getBroadcast(context, i, new Intent(context, HeightMeasureReceiver.class), 0);
            am.cancel(pendingIntent);
            pendingIntent = PendingIntent.getBroadcast(context, i, new Intent(context, UpdatePhotoReceiver.class), 0);
            am.cancel(pendingIntent);
            pendingIntent = PendingIntent.getBroadcast(context, i, new Intent(context, WaterReceiver.class), 0);
            am.cancel(pendingIntent);
        }
    }
}
项目:Botanist    文件:DatabaseManager.java   
/**
 * Set when to remind about birthdays
 * @param context - the current app context
 * @param plant - the plant whose birthday is reminded of
 * @param id - the id of the plant
 */
public void setBirthdayReminder(Context context, Plant plant, int id) {
    Intent intent = new Intent(context, BirthdayReceiver.class);
    intent.putExtra("name", plant.getName());
    intent.putExtra("species", plant.getSpecies());
    intent.putExtra("birthday", plant.getBirthday());
    intent.putExtra("id", id);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, id, intent, 0);
    Calendar now = Calendar.getInstance();
    now.setTimeInMillis(System.currentTimeMillis());
    Calendar birthday = Calendar.getInstance();
    birthday.setTimeInMillis(plant.getBirthday());
    birthday.set(Calendar.YEAR, now.get((Calendar.YEAR)));
    if (birthday.getTimeInMillis() < now.getTimeInMillis()) {
        birthday.set(Calendar.YEAR, now.get((Calendar.YEAR)) + 1);
    }
    AlarmManager am = (AlarmManager)context.getSystemService(ALARM_SERVICE);
    if (am != null) {
        am.set(AlarmManager.RTC_WAKEUP, birthday.getTimeInMillis(), pendingIntent);
    }
}
项目:AutoAirplaneMode    文件:AlarmBroadcastReceiver.java   
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);
}
项目:PeSanKita-android    文件:PersistentAlarmManagerListener.java   
@Override
public void onReceive(Context context, Intent intent) {
  long          scheduledTime = getNextScheduledExecutionTime(context);
  AlarmManager  alarmManager  = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
  Intent        alarmIntent   = new Intent(context, getClass());
  PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0);

  if (System.currentTimeMillis() >= scheduledTime) {
    scheduledTime = onAlarm(context, scheduledTime);
  }

  Log.w(TAG, getClass() + " scheduling for: " + scheduledTime);

  alarmManager.cancel(pendingIntent);
  alarmManager.set(AlarmManager.RTC_WAKEUP, scheduledTime, pendingIntent);
}
项目:siiMobilityAppKit    文件:Notification.java   
/**
 * Schedule the local notification.
 */
public void schedule() {
    long triggerTime = options.getTriggerTime();

    persist();

    // Intent gets called when the Notification gets fired
    Intent intent = new Intent(context, receiver)
            .setAction(options.getIdStr())
            .putExtra(Options.EXTRA, options.toString());

    PendingIntent pi = PendingIntent.getBroadcast(
            context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    if (isRepeating()) {
        getAlarmMgr().setRepeating(AlarmManager.RTC_WAKEUP,
                triggerTime, options.getRepeatInterval(), pi);
    } else {
        getAlarmMgr().set(AlarmManager.RTC_WAKEUP, triggerTime, pi);
    }
}
项目:iosched-reader    文件:SyncUserCommand.java   
private void scheduleSync(Context context, int syncDelay) {
    // Use delay instead of jitter, since we're trying to squelch messages
    int jitterMillis = syncDelay;

    final String debugMessage = "Scheduling next user data sync for " + jitterMillis + "ms";
    LOGI(TAG, debugMessage);

    final Intent intent = new Intent(context, TriggerSyncReceiver.class);
    intent.putExtra(TriggerSyncReceiver.EXTRA_USER_DATA_SYNC_ONLY, true);
    ((AlarmManager) context.getSystemService(Context.ALARM_SERVICE))
            .set(
                    AlarmManager.RTC,
                    System.currentTimeMillis() + jitterMillis,
                    PendingIntent.getBroadcast(
                            context,
                            0,
                            intent,
                            PendingIntent.FLAG_CANCEL_CURRENT)
            );

}
项目:TaipeiTechRefined    文件:AlarmInitReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    Calendar calendar = Calendar.getInstance();
    if (calendar.get(Calendar.HOUR_OF_DAY) > 7) {
        calendar.add(Calendar.DATE, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 7);
    } else {
        calendar.set(Calendar.HOUR_OF_DAY, 7);
    }
    Intent receiver_intent = new Intent(context,
            ActivityCheckReceiver.class);
    receiver_intent.putExtra("action",
            "com.taipeitech.action.ACTIVITY_CHECK");
    PendingIntent pi = PendingIntent.getBroadcast(context, 1,
            receiver_intent, PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager am = (AlarmManager) context
            .getSystemService(Context.ALARM_SERVICE);
    am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pi);
}
项目:Minitask    文件:MyDateTimeUtils.java   
public void ScheduleNotification(Notification notification,
                                 Context context, int notificationID, String dateTime) {
    Intent notificationIntent = new Intent(context, NotificationPublisher.class);
    notificationIntent.putExtra(NOTIFICATION_ID, notificationID);
    notificationIntent.putExtra(NOTIFICATION, notification);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    // parse string parameter to milliseconds for later alarm set
    Date futureInMillis = null;
    try {
        futureInMillis = dateTimeFormatter.parse(dateTime);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC_WAKEUP, futureInMillis.getTime(), pendingIntent);
}
项目:android-crond    文件:Crond.java   
public void scheduleLine(String line, int lineNo) {
    ParsedLine parsedLine = parseLine(line);
    if (parsedLine == null) {
        return;
    }
    ExecutionTime time;
    try {
        time = ExecutionTime.forCron(parser.parse(parsedLine.cronExpr));
    }
    catch (IllegalArgumentException e) {
        return;
    }
    DateTime next = time.nextExecution(DateTime.now());
    Intent intent = new Intent(context, AlarmReceiver.class);
    intent.putExtra(INTENT_EXTRA_LINE_NAME, line);
    intent.putExtra(INTENT_EXTRA_LINE_NO_NAME, lineNo);
    PendingIntent alarmIntent = PendingIntent.getBroadcast(context, lineNo, intent,
            PendingIntent.FLAG_UPDATE_CURRENT); // update current to replace the one used
                                                // for cancelling any previous set alarms
    alarmManager.setExact(AlarmManager.RTC_WAKEUP, next.getMillis(), alarmIntent);
    IO.logToLogFile(context.getString(R.string.log_scheduled_v2, lineNo + 1, parsedLine.runExpr,
            DateTimeFormat.forPattern("YYYY-MM-dd HH:mm:ss.SSSS").print(next)));
}
项目:androidtv-sample    文件:RecommendationReceiver.java   
private void scheduleRecommendationUpdate(Context context) {
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent recommendationIntent = new Intent(context, UpdateRecommendationsService.class);
    PendingIntent alarmIntent = PendingIntent.getService(context, 0, recommendationIntent, 0);

    alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, INITIAL_DELAY,
            AlarmManager.INTERVAL_HALF_HOUR, alarmIntent);
}
项目:SmingZZick_App    文件:AttackManager.java   
public void refreshAttackAlarm(Context context) {
    if (attackDatas == null) {
        return;
    }
    List<AttackData> copied = new ArrayList<>(attackDatas);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    for (AttackData attackData : copied) {
        cancelAlarm(context, attackData);
        registAttack(context, alarmManager, attackData);
    }
}
项目:ImHome    文件:AlarmUtils.java   
@RequiresApi(api = Build.VERSION_CODES.N)
public static void setAlarm(Context context,int hour, int minute, int second) {
    Calendar calendar = Calendar.getInstance();
    Calendar rightNow = Calendar.getInstance();
    calendar.set(Calendar.HOUR, hour);
    int timeOffset = hour - calendar.get(Calendar.HOUR);
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR, hour - timeOffset);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.SECOND, second);

    Intent intent = new Intent(context, AlarmReceiver.class);
    pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
    alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    //set the alarm repeat one day
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,
            calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
    Log.i("setting", String.valueOf(calendar.getTime()));
    Log.i("actual", String.valueOf(rightNow.getTime()));
}
项目:EveryCoolPic    文件:Utils.java   
public static void setEnable (boolean enable, Context context) {
    AlarmManager manager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
    PendingIntent pendingIntent = PendingIntent.getService(context, 0, new Intent(context, WallpaperService.class), 0);
    if (!enable) {
        manager.cancel(pendingIntent);
    } else {
        manager.setInexactRepeating(AlarmManager.RTC_WAKEUP,
                System.currentTimeMillis(),
                AlarmManager.INTERVAL_DAY, pendingIntent);
    }
}
项目:nifi-android-s2s    文件:MainActivity.java   
public void cancelAlarms(View view) {
    AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
    for (PendingIntentWrapper pendingIntentWrapper : demoAppDB.getPendingIntents()) {
        PendingIntent pendingIntent = pendingIntentWrapper.getPendingIntent();
        if (pendingIntent != null) {
            alarmManager.cancel(pendingIntent);
        }
        demoAppDB.deletePendingIntent(pendingIntentWrapper.getRowId());
    }
}
项目:HappyWeather    文件:AutoUpdateService.java   
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    updateWeather();
    updateBingPic();
    AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE);
    int anHour = 8 * 60 * 60 * 1000; // 这是8小时的毫秒数
    long triggerAtTime = SystemClock.elapsedRealtime() + anHour;
    Intent i = new Intent(this, AutoUpdateService.class);
    PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
    manager.cancel(pi);
    manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, pi);
    return super.onStartCommand(intent, flags, startId);
}
项目:chromium-for-android-56-debug-video    文件:ExponentialBackoffScheduler.java   
/**
 * 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;
}
项目:GitHub    文件:WatchDogService.java   
/**
 * 用于在不需要服务运行的时候取消 Job / Alarm / Subscription.
 *
 * 因 WatchDogService 运行在 :watch 子进程, 请勿在主进程中直接调用此方法.
 * 而是向 WakeUpReceiver 发送一个 Action 为 WakeUpReceiver.ACTION_CANCEL_JOB_ALARM_SUB 的广播.
 */
public static void cancelJobAlarmSub() {
    if (!DaemonEnv.sInitialized) return;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        JobScheduler scheduler = (JobScheduler) DaemonEnv.sApp.getSystemService(JOB_SCHEDULER_SERVICE);
        scheduler.cancel(HASH_CODE);
    } else {
        AlarmManager am = (AlarmManager) DaemonEnv.sApp.getSystemService(ALARM_SERVICE);
        if (sPendingIntent != null) am.cancel(sPendingIntent);
    }
    if (sDisposable != null) sDisposable.dispose();
}
项目:DoList    文件:Festival.java   
public void setclickalarm(int id) {
    if ((!database.isOpen()) || database == null) {
        database = openOrCreateDatabase("db.db", MODE_PRIVATE, null);// 打开数据库
    }
    int requestCode = 0;
    // ------------------------------
    String table = "festival";
    String[] columns = { "name", "date", "flag", "dataid" };
    String selection = null;
    String[] selectionArgs = null;
    Cursor cursor = database.query(table, columns, selection,
            selectionArgs, null, null, null);
    cursor.moveToPosition(id);// 移动到id行
    int idValue = id;
    int contentColumnIndex = cursor.getColumnIndex("name");
    String contentValue = cursor.getString(contentColumnIndex); // 得到id行的内容
    int alarmColumnIndex = cursor.getColumnIndex("date");
    String alarmValue = cursor.getString(alarmColumnIndex); // 得到id行的闹铃时间
    requestCode = idValue;
    // ---------------------------------------------------------------------
    alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    Intent intent = new Intent(Festival.this, ClockActivity.class);
    intent.putExtra("content", contentValue);// 传递内容
    intent.putExtra("alarmtime", alarmValue);// 传递闹铃时间
    pi = PendingIntent.getActivity(Festival.this, requestCode, intent,
            PendingIntent.FLAG_CANCEL_CURRENT); // 根据id设置不同的闹钟
    Calendar alarmTime = Calendar.getInstance();
    long alarmdatetime = changedatetime(alarmValue); // 将时间转换为long型
    alarmManager.set(AlarmManager.RTC_WAKEUP, alarmdatetime, pi);
    Toast.makeText(getApplicationContext(), "闹钟设置好了", Toast.LENGTH_LONG)
            .show();
    database.close();// 关闭数据库连接
}
项目:AndroidBookTest    文件:AutoUpdateService.java   
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    updateWeather();
    updateBingPic();
    AlarmManager manager=(AlarmManager)getSystemService(ALARM_SERVICE);
    int anHour=1*60*60*1000;//这是1小时的毫秒数
    long triggerAtTime= SystemClock.elapsedRealtime()+anHour;
    Intent i=new Intent(this,AutoUpdateService.class);
    PendingIntent pi=PendingIntent.getService(this,0,i,0);
    manager.cancel(pi);
    manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,triggerAtTime,pi);
    return super.onStartCommand(intent,flags,startId);
}
项目:project-weather    文件:AutoUpdateService.java   
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    updateWeather();
    updateBingPic();
    AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE);
    int anHour = 8 * 60 * 60 * 1000; // 8小时的毫秒数
    long triggerTime = SystemClock.elapsedRealtime() + anHour;
    Intent i = new Intent(this, AutoUpdateService.class);
    PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
    manager.cancel(pi);
    manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerTime, pi);
    return super.onStartCommand(intent, flags, startId);
}
项目:Linphone4Android    文件:Compatibility.java   
public static void scheduleAlarm(AlarmManager alarmManager, int type, long triggerAtMillis, PendingIntent operation) {
    if (Version.sdkAboveOrEqual(Version.API19_KITKAT_44)) {
        ApiNineteenPlus.scheduleAlarm(alarmManager, type, triggerAtMillis, operation);
    } else {
        ApiElevenPlus.scheduleAlarm(alarmManager, type, triggerAtMillis, operation);
    }
}
项目:leoapp-sources    文件:NotificationServiceWrapper.java   
private void reschedule() {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        UtilsController c = Utils.getController();
        c.getAlarmManager().cancel(c.getTimetableReference());
        Calendar calendar = Calendar.getInstance();

        NotificationTime time = Utils.getNotificationTime(NotificationType.TIMETABLE);
        calendar.add(Calendar.DATE, 1);
        calendar.set(Calendar.HOUR_OF_DAY, time.hours);
        calendar.set(Calendar.MINUTE, time.minutes);

        c.getAlarmManager().setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), c.getTimetableReference());
    }
}
项目:VulcanOTA    文件:AppConfig.java   
public static void persistUpdateIntervalIndex(int intervalIndex, Context context) {
    long intervalValue;
    switch(intervalIndex) {
        case 0:
            intervalValue = 0;
            break;
        case 1:
            intervalValue = AlarmManager.INTERVAL_HOUR;
            break;
        case 2:
            intervalValue = AlarmManager.INTERVAL_HALF_DAY;
            break;
        case 3:
            intervalValue = AlarmManager.INTERVAL_DAY;
            break;
        default:
            intervalValue = OTAListener.DEFAULT_INTERVAL_VALUE;
            break;
    }

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    sharedPreferences.edit().putLong(UPDATE_INTERVAL, intervalValue).apply();
    if (intervalValue > 0) {
        WakefulIntentService.cancelAlarms(context);
        WakefulIntentService.scheduleAlarms(new OTAListener(), context, true);
        OTAUtils.toast(R.string.autoupdate_enabled, context);
    } else {
        WakefulIntentService.cancelAlarms(context);
        OTAUtils.toast(R.string.autoupdate_disabled, context);
    }
}
项目:AlarmWithL-T    文件:SettingFragment.java   
private void makeDate() throws NullPointerException {
    mData.setLocation(isLocation);
    if (isLocation) {
        Log.d(TAG, "Location is true");
        // Check Permission
        if (ActivityCompat.checkSelfPermission(getActivity().getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            new NullPointerException();
        }

        LocationServices.GeofencingApi.addGeofences(mClient, settingGeofence(mData), settingAlarm(mData));
        mData.setLatitude(mTargetLocation.latitude);
        mData.setLongitude(mTargetLocation.longitude);
        Log.i("RegistrationLocation", "Lat = " + mData.getLatitude() + ", Lng = " + mData.getLongitude());
    }
    if (isDate) {
        Log.d(TAG, "Data is true");

        mSchedule.set(Calendar.SECOND, 0);
        mData.setDate(mSchedule.getTime()); // Set when show

        // Debugging data when show Alarm
        Log.i("mSchedule", mSchedule.get(Calendar.YEAR) + "/" + (mSchedule.get(Calendar.MONTH) + 1) + "/" + mSchedule.get(Calendar.DAY_OF_MONTH));
        Log.i("mSchedule", mSchedule.get(Calendar.HOUR_OF_DAY) + ":" + mSchedule.get(Calendar.MINUTE));

        AlarmManager manager = (AlarmManager) getActivity().getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        if (Build.VERSION.SDK_INT >= 18) {
            manager.set(AlarmManager.RTC_WAKEUP, mSchedule.getTimeInMillis(), settingAlarm(mData));
        } else if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 23) {
            manager.setExact(AlarmManager.RTC_WAKEUP, mSchedule.getTimeInMillis(), settingAlarm(mData));
        } else {
            setExactAndAllowWhileIdle(manager);
        }

    }
}
项目:leoapp-sources    文件:NotificationServiceWrapper.java   
private void reschedule() {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        UtilsController c = Utils.getController();
        c.getAlarmManager().cancel(c.getStimmungsbarometerReference());
        Calendar calendar = Calendar.getInstance();

        NotificationTime time = Utils.getNotificationTime(NotificationType.MOOD);
        calendar.add(Calendar.DATE, 1);
        calendar.set(Calendar.HOUR_OF_DAY, time.hours);
        calendar.set(Calendar.MINUTE, time.minutes);

        c.getAlarmManager().setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), c.getStimmungsbarometerReference());
    }
}
项目:UnforgetIt    文件:AlarmReceiver.java   
public void cancelAlarm(Context context, Task task) {
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    PendingIntent alarmIntent = intentMap.get(task.getId().intValue());
    if (alarmIntent != null) {
        Log.d(this.getClass().getName(), "Cancel " + alarmIntent);
        alarmManager.cancel(alarmIntent);
        intentMap.remove(alarmIntent);
    }
}
项目:10-bitClockWidget    文件:ClockWidgetUpdateService.java   
private void setUpdateAlarm() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.SECOND, 0);
    calendar.add(Calendar.MINUTE, 1);
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    if(Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2)
        alarmManager.setExact(AlarmManager.RTC, calendar.getTimeInMillis(), createClockUpdateIntent(this));
    else
        alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), createClockUpdateIntent(this));
}
项目:leoapp-sources    文件:NotificationAlarmHandler.java   
private static AlarmManager getAlarmManager() {
    if (Utils.getController().getAlarmManager() == null) {
        AlarmManager am = (AlarmManager) Utils.getContext().getSystemService(Context.ALARM_SERVICE);
        Utils.getController().registerAlarmManager(am);
    }
    return Utils.getController().getAlarmManager();
}
项目:NoticeDog    文件:AppMonitor.java   
void stopMonitoring() {
    if (this.alarmPendingIntent != null) {
        Log.d(TAG, "Stopping app monitoring");
        this.lastSeenRunningApps.clear();
        ((AlarmManager) this.context.getSystemService("alarm")).cancel(this.alarmPendingIntent);
        this.alarmPendingIntent.cancel();
        this.alarmPendingIntent = null;
    }
}