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
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;
7
CodeRank
This code example shows how to use the following methods:set
			alarmManager.cancel(goAwayPendingIntent);
			alarmManager.cancel(goXaPendingIntent);
			AccountManager.getInstance().wakeUp(); 
		} else if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) {
			if (goAway >= 0)
				alarmManager.set(AlarmManager.RTC_WAKEUP, getTime(goAway),
						goAwayPendingIntent);
			if (goXa >= 0)
				alarmManager.set(AlarmManager.RTC_WAKEUP, getTime(goXa),
						goXaPendingIntent);
		} 
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:set
	} 
	public void setOnetimeTimer(Context context){
		AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
		Intent intent = new Intent(context, AlarmManagerBroadcastReceiver.class);
		PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
		am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), pi);
	} 
} 
6
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());
            } 
        } 
6
CodeRank
This code example shows how to use the following methods:set
    public void setOnetimeTimer(Context context){
    	AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(context, AlarmManagerBroadcastReceiver.class);
        intent.putExtra(ONE_TIME, Boolean.TRUE);
        PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
        am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), pi);
    } 
} 
6
CodeRank
This code example shows how to use the following methods:cancel, set
			c.add(Calendar.MINUTE, interval);
		} 
 
		AlarmManager alarm = (AlarmManager) context
				.getSystemService(Context.ALARM_SERVICE);
		alarm.cancel(pending);
		alarm.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), pending);
	} 
	 
	public static void unschedule(Context context) {
		Intent intent = new Intent(context, CheckMessageService.class);
		PendingIntent pending = PendingIntent.getService(context, 0, intent, 0);
		AlarmManager alarm = (AlarmManager) context
				.getSystemService(Context.ALARM_SERVICE);
		alarm.cancel(pending);
	} 
	 
	public static int MESSAGE_NOTIFICATION_ID = 0;
	 
	private void showNotification(PendingIntent intent, int notificationId,
7
CodeRank
This code example shows how to use the following methods:set
 
  private void createAlarmForNextUpdate() { 
    DateTime plusHours = new DateTime().plusHours(24);
    Intent ultimateIntent = new Intent(this, VersionCheckerService.class);
    PendingIntent intent = PendingIntent.getService(getApplicationContext(), 0, ultimateIntent, 0);
    alarmManager.set(AlarmManager.RTC_WAKEUP, plusHours.getMillis(), intent);
    Log.i(RESULTS_SERVICE_TAG, "Created alarm for VersionCheckerService. Time: "
        + plusHours.toString());
 
  } 
 
} 
6
CodeRank
This code example shows how to use the following methods:set
	 
		Intent i = new Intent(ctx, NotificationsAlarmReceiver.class);
		PendingIntent pendingIntent = PendingIntent.getBroadcast(ctx, REQ_CODE, i, 0);
 
		alarmManager = (AlarmManager) ctx.getSystemService(Service.ALARM_SERVICE);
		alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (5 * 1000), pendingIntent);
		 
		//Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show(); 
		 
	} 
	 
	void cancelAlarm(Context ctx) {
		Intent i = new Intent(ctx, NotificationsAlarmReceiver.class);
		PendingIntent pendingIntent = PendingIntent.getBroadcast(ctx, REQ_CODE, i, 0);
		alarmManager.cancel(pendingIntent);
	} 
 
	public static boolean setupAlarmData(Context context) {
 
		// Clear Shuttle alarms 
6
CodeRank
This code example shows how to use the following methods:cancel, set
		PendingIntent pendingIntent = PendingIntent.getBroadcast(
				context.getApplicationContext(), 1, intent, 0);
		AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
		 
		//Cancel any previous alarms 
		alarmManager.cancel(pendingIntent);
		 
		//Create new alarms 
		alarmManager.set(AlarmManager.RTC_WAKEUP, timeMillis, pendingIntent);
	} 
	 
	public static Calendar getAlarmCalendar(SharedPreferences settings){
		Calendar now=Calendar.getInstance();
		int hour = settings.getInt("baseHour", 0);
		int minute = settings.getInt("baseMinute", 0);
		 
		Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, minute);
        calendar.set(Calendar.SECOND, 0);
7
CodeRank
This code example shows how to use the following methods:set
					// get alarm manager 
					AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
					 
					// set alarm to turn off BLN 
					PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 1, new Intent("mobi.cyann.nstools.SHUTDOWN_BLN"), PendingIntent.FLAG_CANCEL_CURRENT);
					alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + blnTimeout, pendingIntent);
				} 
			} 
			WakeLock.release(); 
		} 
	} 
 
	class AlarmReceiver extends BroadcastReceiver {
		@Override 
		public void onReceive(Context context, Intent intent) {
			WakeLock.acquire(context);
			Log.d(LOG_TAG, "shutdown BLN now");
			SysCommand.getInstance().writeSysfs("/sys/class/misc/backlightnotification/notification_led", "0"); 
			WakeLock.release(); 
		} 
6
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(
6
CodeRank
This code example shows how to use the following methods:set
		intent.setClass(getApplicationContext(), DataService.class);
		PendingIntent pendingIntent=PendingIntent.getService(getApplicationContext(), 1, intent, PendingIntent.FLAG_ONE_SHOT);
		AlarmManager alarmManager=(AlarmManager)getSystemService(ALARM_SERVICE);
		long now= System.currentTimeMillis();
		//start after 1.5 minutes/ 90 seconds 
		alarmManager.set(AlarmManager.RTC_WAKEUP, (now+ 9000), pendingIntent);
	} 
	 
	 
	private String[] FIRST_NAMES={"John","Jack","Jim","Robert","Jane","Sally","Henrietta","Juliet"};
	private String[] LAST_NAMES={"Smith","Jones","Mueller","Doe"};
	private String[] DOMAINS={"@nowhere.com","@hell.com","@heaven.com","@randomland.it"};
	 
} 
6
CodeRank
This code example shows how to use the following methods:set
		long time=System.currentTimeMillis();
		time=time+(10*60*1000);
		Intent intent = new Intent(mContext,NewsreaderService.class);
		PendingIntent operation=PendingIntent.getService(mContext,0,intent,PendingIntent.FLAG_ONE_SHOT);
		Log.i(_TAG,"scheduling run of newsreader service for >"+java.text.DateFormat.getInstance().format(new Date(time)));
		am.set(AlarmManager.RTC_WAKEUP,time,operation);
 
	 
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:set
			String updateInterval = prefs.getString("update_interval", "" + FREQUENCY);
			m_interval = Long.parseLong(updateInterval);
		} 
			 
		if (m_interval > 0 && process){
			mgr.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + m_interval, pi);
		} 
	} 
 
	public void sendWakefulWork(Context ctxt) {
		WakefulIntentService.sendWakefulWork(ctxt, CheckService.class);
	} 
} 
6
CodeRank
This code example shows how to use the following methods:cancel, set
        PendingIntent pendingIntent = PendingIntent.getService(this, 0, new Intent(this, UpdateService.class),
                PendingIntent.FLAG_ONE_SHOT);
        long trigger = System.currentTimeMillis() + time;
 
        AlarmManager alarmManager = getAlarmManager();
        alarmManager.cancel(pendingIntent);
        alarmManager.set(AlarmManager.RTC_WAKEUP, trigger, pendingIntent);
    } 
 
    private AlarmManager getAlarmManager() {
        return (AlarmManager) getSystemService(ALARM_SERVICE);
    } 
 
    public void showMessage(int messageId) {
        Toast.makeText(this, messageId, Toast.LENGTH_LONG).show();
    } 
 
} 
6
CodeRank
This code example shows how to use the following methods:set
     */ 
    public static void runNotificationServiceDelayed(Context context) {
        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);
    } 
 
    public static String toSHA1(Context context, String message) {
        try { 
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            byte[] messageBytes = message.getBytes("UTF-8");
            byte[] digest = md.digest(messageBytes);
 
            String result = "";
            for (int i = 0; i < digest.length; i++) {
                result += Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1);
            } 
 
6
CodeRank
This code example shows how to use the following methods:cancel, set
        am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    } 
 
    public void register(Context context, long millis, String index) {
        cancel(); 
        am.set(AlarmManager.RTC_WAKEUP, millis, getPendingIntent(context, index));
    } 
 
    public void cancel() { 
        if (cacheIntent != null) {
            am.cancel(cacheIntent);
            cacheIntent= null;
        } 
    } 
 
    private PendingIntent getPendingIntent(Context context, String index) {
        Intent intent = new Intent(context, MyAlarmActivity.class);
        cacheIntent = PendingIntent.getActivity(
            context,
            0, 
6
CodeRank
This code example shows how to use the following methods:set
		int mo = now.get(Calendar.MONTH);
		int yr = now.get(Calendar.YEAR);
		now.set(yr, mo, day, 0, 0);
		 
		// set the alarm 
		am.set(AlarmManager.RTC_WAKEUP, now.getTimeInMillis(), sender);
	} 
} 
6
CodeRank
This code example shows how to use the following methods:cancel, set
			long timeoutMs = Integer.valueOf((String)newValue) * 60 * 1000;
			Intent serviceIntent = new Intent(getActivity(), UpdateService.class);
        	PendingIntent pendingIntent = PendingIntent.getService(
        			getActivity(), 0, serviceIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        	AlarmManager am = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
        	am.cancel(pendingIntent);
        	am.set(AlarmManager.RTC_WAKEUP, timeoutMs, pendingIntent);
			 
			return true; 
		} 
		return false; 
	} 
} 
6
CodeRank
This code example shows how to use the following methods:cancel, set
    } else { 
      Log.w("PeriodicActionUtils", "Scheduling for time found in preferences: " + scheduledTime
        + " (" + clazz.getSimpleName() + ")");
    } 
 
    am.cancel(sender);
    am.set(AlarmManager.RTC_WAKEUP, scheduledTime, sender);
 
    Log.w("PeriodicActionUtils", "Scheduled for: " + scheduledTime
      + " (" + clazz.getSimpleName() + ")");
  } 
} 
6
CodeRank

Related AlarmManager set Questions & Answers:

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