AlarmManager set - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for AlarmManager set method.

This code example shows how to use the following methods:cancel, set
 
    public static void scheduleReengagementAlarm(Context context) {
        AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(BROADCAST_SHOW_REENGAGEMENT);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, intent, 0);
        am.cancel(pendingIntent);
 
        long time = getNextReminderTime();
        am.set(AlarmManager.RTC_WAKEUP, time, pendingIntent);
    } 
 
    private static long getNextReminderTime() { 
        int reengagementReminders = Preferences.getInt(PREF_REENGAGEMENT_COUNT, 1);
        int days;
        if (DateUtilities.now() - Preferences.getLong(AstridPreferences.P_FIRST_LAUNCH, 0) > DateUtilities.ONE_DAY * 30) { // Installed longer than 30 days
            // Sequence: every 6, 8, 10 days 
            days = Math.min(10, 4 + 2 * reengagementReminders);
        } else { 
            // Sequence: every 2, 3, 4, 5 days 
            days = Math.min(5, 1 + reengagementReminders);
9
CodeRank
This code example shows how to use the following methods:cancel, set
    } else { 
      Log.w("DirectoryUpdateReceiver", "Scheduling for time found in preferences: " +
            scheduledTime);
    } 
 
    am.cancel(sender);
    am.set(AlarmManager.RTC_WAKEUP, scheduledTime, sender);
 
    Log.w("DirectoryUpdateReceiver", "Scheduled for: " + scheduledTime);
  } 
} 
9
CodeRank
This code example shows how to use the following methods:cancel, set
        AlarmManager alarmManager =
              (AlarmManager) context.getSystemService (Context.ALARM_SERVICE);
 
        if (pending != null) {
            // Cancel any previous alarms that do the same thing. 
            alarmManager.cancel(pending);
            Log.d(TAG, "setDiscoverableAlarm(): cancel prev alarm");
        } 
        pending = PendingIntent.getBroadcast(
            context, 0, intent, 0);
 
        alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, pending);
    } 
 
    static void cancelDiscoverableAlarm(Context context) {
        Log.d(TAG, "cancelDiscoverableAlarm(): Enter");
 
        Intent intent = new Intent(INTENT_DISCOVERABLE_TIMEOUT);
        intent.setClass(context, BluetoothDiscoverableTimeoutReceiver.class);
        PendingIntent pending = PendingIntent.getBroadcast(
9
CodeRank
This code example shows how to use the following methods:set
            // postpone notification service launch a minute, 
            // we don't want to slow down booting 
            AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
            Intent i = new Intent(context, OnAlarmReceiver.class);
            PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
            am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1
                    * DateUtils.MINUTE_IN_MILLIS, pi);
            Log.d("OnAlarmReceiver", "Postponing service launch");
        } else { 
            // run the notification service right away 
            Log.d("OnAlarmReceiver", "Run notifications service right away");
            Utils.runNotificationService(context);
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:set
		 
		Intent intent = new Intent(this, TimeclockService.class);
		intent.putExtra("action", TIMECLOCK_TIMEOUT);
		this.timeoutIntent = PendingIntent.getService(appInst, 2,
				intent, 0);
		alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
				+ time, timeoutIntent);
	} 
	 
	private void unsetAlarms() { 
		if(this.updateIntent != null) {
			alarmManager.cancel(this.updateIntent);
			this.updateIntent = null;
		} 
		 
		if(this.timeoutIntent != null) {
			alarmManager.cancel(this.timeoutIntent);
			this.timeoutIntent = null;
		} 
	} 
7
CodeRank
This code example shows how to use the following methods:cancel, set
		// Create a new PendingIntent and add it to the AlarmManager 
		Intent intent = new Intent(Intent.ACTION_RUN);
		PendingIntent pendingIntent = PendingIntent.getService(this, id,
				intent, PendingIntent.FLAG_CANCEL_CURRENT);
		AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
		am.cancel(pendingIntent);
		am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
		Log.d(TAG, "Scheduled sync");
	} 
 
	@Override 
	public IBinder onBind(Intent intent) {
		return null; 
	} 
 
} 
8
CodeRank
This code example shows how to use the following methods:cancel, set, setRepeating
 
		if (command.contains("Start Alarm")) {
			alarmManager.set(AlarmManager.RTC_WAKEUP, time, pi);
		} else if (command.contains("Stop Alarm")) {
			pi.cancel(); 					// Cancel the pendingIntent.
			alarmManager.cancel(pi); 		// Cancel the alarm.
			 
			// If more times with a timeReminder exist, start a new alarm. 
			if (time != 0) alarmManager.set(AlarmManager.RTC_WAKEUP, time, pi);
		} else 
			Log.e("AlarmManagerService", "Command contained unknown value");
	} 
 
	/** 
	 * Method for starting or stopping the position alarm. 
	 * @param command decides whether to start or stop the alarm. 
	 */ 
	private void positionAlarm(String command) {
		// Let the receiver know its a position-alarm. 
		alarmReceiverIntent.putExtra("alarmType", "position");

7
CodeRank
This code example shows how to use the following methods:set
                Intent retryIntent = new Intent(C2DM_RETRY);
                PendingIntent retryPIntent = PendingIntent.getBroadcast(context, 
                        0 /*requestCode*/, retryIntent, 0 /*flags*/);
                 
                AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
                am.set(AlarmManager.ELAPSED_REALTIME,
                        backoffTimeMs, retryPIntent);
 
                // Next retry should wait longer. 
                backoffTimeMs *= 2;
                C2DMessaging.setBackoff(context, backoffTimeMs);
            }  
        } else { 
            try { 
                onRegistered(context, registrationId);
                C2DMessaging.setRegistrationId(context, registrationId);
            } catch (IOException ex) {
                Log.e(TAG, "Registration error " + ex.getMessage());
            } 
        } 
7
CodeRank
This code example shows how to use the following methods:set
                intentFilter, null, new Handler(looper));
    } 
 
    private void scheduleUpdateIdleMaintenanceState(long delayMillis) {
        final long triggetRealTimeMillis = SystemClock.elapsedRealtime() + delayMillis;
        mAlarmService.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggetRealTimeMillis,
                mUpdateIdleMaintenanceStatePendingIntent);
    } 
 
    private void unscheduleUpdateIdleMaintenanceState() { 
        mAlarmService.cancel(mUpdateIdleMaintenanceStatePendingIntent);
    } 
 
    private void updateIdleMaintenanceState() { 
        if (mIdleMaintenanceStarted) {
            // Idle maintenance can be interrupted by user activity, or duration 
            // time out, or low battery. 
            if (!lastUserActivityPermitsIdleMaintenanceRunning() 
                    || !batteryLevelAndMaintenanceTimeoutPermitsIdleMaintenanceRunning()) { 
                unscheduleUpdateIdleMaintenanceState(); 
6
CodeRank
This code example shows how to use the following methods:cancel, set
    public IBinder onBind(Intent intent) {
        return null; 
    } 
 
    private void schedule(PendingIntent intent, long timeout) {
        mAM.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeout, intent);
    } 
 
    private void cancelTimeout() { 
        removeStickyBroadcast(new Intent(ACTION_TIMER_UPDATE));
        mRebootTimeout = -1;
        mAM.cancel(mTimerUpdateIntent);
    } 
 
    private Notification createNotification() {
        Notification notification = new Notification(android.R.drawable.stat_notify_error, null, System.currentTimeMillis());
        notification.defaults |= Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE;
        notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_SHOW_LIGHTS;
        notification.ledARGB = Color.RED;
        notification.ledOnMS = 1000;
8
CodeRank

Related AlarmManager set Questions & Answers:

set Method Overview
Schedule an alarm.
See Code Examples for other Android AlarmManager Methods: