public void alarmFacebookUserComming(Message callbackMessage) { Log.d(TAG, "alarmFacebookUserComming"); Message msg = handler.obtainMessage(FACEBOOK_FRIENDS_GET); if (callbackMessage != null) { msg.getData().putParcelable(CALLBACK, callbackMessage); msg.getData().putLong("hisuid", callbackMessage.getData().getLong("hisuid", -1)); } handler.sendMessageDelayed(msg, 1 * 1000); long nexttime = System.currentTimeMillis() + getFriendsTimeout() * 1000L; if (SNSService.TEST_LOOP) { nexttime = System.currentTimeMillis() + 90 * 1000; } AlarmManager alarmMgr = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(); i.setClassName("com.ast.free", "com.ast.free.service.SNSService"); i.setAction("com.ast.free.intent.action.FACEBOOK_USER"); PendingIntent userpi = PendingIntent.getService( mContext.getApplicationContext(), 0, i, PendingIntent.FLAG_CANCEL_CURRENT); alarmMgr.set(AlarmManager.RTC_WAKEUP, nexttime, userpi); }
/** * In order to update notification from the AlarmSender. * * @param oldName <code>String</code> - old name * @param oldDescription <code>String</code> - old description * @param oldDate <code>String</code> - old date * @param newName <code>String</code> - new name * @param newDescription <code>String</code> - new description * @param newDate <code>String</code> - new date */ @android.webkit.JavascriptInterface public void updateAlarmPerToDoItem( String oldName, String oldDescription, String oldDate, String newName, String newDescription, String newDate) { long oldTime = ParseDateToTimeStamp(oldDate); Intent oldIntent = new Intent(MainActivity.this, NotificationService.class); oldIntent.putExtra("name", oldName); oldIntent.putExtra("description", oldDescription); oldIntent.putExtra("time", oldTime); int oldId = (oldName + oldDescription + oldTime).hashCode(); oldIntent.setData(Uri.parse(String.valueOf(oldId))); PendingIntent oldPendingIntent = PendingIntent.getService( MainActivity.this, 0, oldIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.cancel(oldPendingIntent); long newTime = ParseDateToTimeStamp(newDate); Intent newIntent = new Intent(MainActivity.this, NotificationService.class); oldIntent.putExtra("name", newName); oldIntent.putExtra("description", newDescription); oldIntent.putExtra("time", newTime); int newId = (newName + newDescription + newTime).hashCode(); newIntent.setData(Uri.parse(String.valueOf(newId))); PendingIntent newPendingIntent = PendingIntent.getService( MainActivity.this, 0, newIntent, PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.set(AlarmManager.RTC_WAKEUP, newTime, newPendingIntent); }
@Test public void cancel_removesMatchingPendingIntents() { Intent newIntent = new Intent(Robolectric.application.getApplicationContext(), String.class); PendingIntent pendingIntent = PendingIntent.getBroadcast( Robolectric.application.getApplicationContext(), 0, newIntent, PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.set(AlarmManager.RTC, 1337, pendingIntent); Intent newIntent2 = new Intent(Robolectric.application.getApplicationContext(), Integer.class); PendingIntent pendingIntent2 = PendingIntent.getBroadcast( Robolectric.application.getApplicationContext(), 0, newIntent2, PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.set(AlarmManager.RTC, 1337, pendingIntent2); assertEquals(2, shadowAlarmManager.getScheduledAlarms().size()); Intent newIntent3 = new Intent(Robolectric.application.getApplicationContext(), String.class); PendingIntent newPendingIntent = PendingIntent.getBroadcast( Robolectric.application.getApplicationContext(), 0, newIntent3, PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.cancel(newPendingIntent); assertEquals(1, shadowAlarmManager.getScheduledAlarms().size()); }
public static void LaunchAt(Context in_context, WorkingTime wrk_time) { Calendar to_fire = wrk_time.start_date; Calendar to_kill = wrk_time.stop_date; MUUDebug.Log(cl_nm, "Start time " + to_fire.getTime().toString()); MUUDebug.Log(cl_nm, "Stop time " + to_kill.getTime().toString()); AlarmManager alarmManager = (AlarmManager) in_context.getSystemService(Context.ALARM_SERVICE); Intent serv_intent = new Intent(in_context, ChkPrice.class); PendingIntent pendingIntent = PendingIntent.getService( in_context.getApplicationContext(), SERV_START_REQ_CODE, serv_intent, PendingIntent.FLAG_CANCEL_CURRENT); // Flag might be adjusted Intent killer = new Intent(in_context, SQServiceKiller.class); PendingIntent sender = PendingIntent.getBroadcast( in_context.getApplicationContext(), SERV_KILLER_REQ_CODE, killer, PendingIntent.FLAG_CANCEL_CURRENT); alarmManager.cancel(pendingIntent); alarmManager.cancel(sender); alarmManager.set(AlarmManager.RTC_WAKEUP, to_fire.getTimeInMillis(), pendingIntent); alarmManager.set(AlarmManager.RTC_WAKEUP, to_kill.getTimeInMillis(), sender); }
@Test public void setShouldReplaceDuplicates() { alarmManager.set( AlarmManager.ELAPSED_REALTIME, 0, PendingIntent.getActivity(activity, 0, new Intent(activity, activity.getClass()), 0)); alarmManager.set( AlarmManager.ELAPSED_REALTIME, 0, PendingIntent.getActivity(activity, 0, new Intent(activity, activity.getClass()), 0)); assertEquals(1, shadowAlarmManager.getScheduledAlarms().size()); }
@Override public final void onReceive(final Context context, final Intent intent) { if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { SharedPreferences sharedPreferences = context.getSharedPreferences(WeatherSettings.WEATHER_SETTING, 0); boolean reset = sharedPreferences.getBoolean(WeatherSettings.RESET_KEY, false); Intent service = new Intent(context, ActionBootService.class); startWakefulService(context, service); if (reset == true) { Calendar myCal = Calendar.getInstance(); myCal.set(Calendar.HOUR_OF_DAY, MainActivity.RESET_HOUR); myCal.set(Calendar.MINUTE, MainActivity.RESET_MINUTE); Intent someIntent = new Intent(context.getApplicationContext(), ResetAlarmReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast( context.getApplicationContext(), MainActivity.REPEATING, someIntent, 0); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, myCal.getTimeInMillis(), pendingIntent); } } }
/** Schedules an alarm to go off a few minutes before this talk. */ private void scheduleNotification(Talk talk) { // We need to know the time slot of the talk, so fetch its data if we haven't already. if (!talk.isDataAvailable()) { Talk.getInBackground( talk.getObjectId(), new GetCallback<Talk>() { @Override public void done(Talk talk, ParseException e) { if (talk != null) { scheduleNotification(talk); } } }); return; } // Figure out what time we need to set the alarm for. Date talkStart = null != talk.getSlot() ? talk.getSlot().getStartTime() : null; if (BuildConfig.DEBUG) { Logger.getLogger(getClass().getName()).log(Level.INFO, "Registering alarm for " + talkStart); } long fiveMinutesBefore = null != talkStart ? talkStart.getTime() - (5000 * 60) : Long.MAX_VALUE; if (fiveMinutesBefore < System.currentTimeMillis()) { return; } // Register the actual alarm. AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pendingIntent = getPendingIntent(talk); manager.set(AlarmManager.RTC_WAKEUP, fiveMinutesBefore, pendingIntent); }
private void refresh() { Intent intent = new Intent(this, SplashActivity.class); // CampusdishclientActivity.class); PendingIntent p = PendingIntent.getActivity(this, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK); AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis(), p); System.exit(0); }
/** * Schedules alarms for a single task * * @param shouldPerformPropertyCheck whether to check if task has requisite properties */ @SuppressWarnings("nls") private void scheduleAlarm(Metadata alarm) { if (alarm == null) return; long taskId = alarm.getValue(Metadata.TASK); int type = ReminderService.TYPE_ALARM; Context context = ContextManager.getContext(); Intent intent = new Intent(context, Notifications.class); intent.setType("ALARM" + Long.toString(taskId)); // $NON-NLS-1$ intent.setAction(Integer.toString(type)); intent.putExtra(Notifications.ID_KEY, taskId); intent.putExtra(Notifications.TYPE_KEY, type); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0); long time = alarm.getValue(AlarmFields.TIME); if (time == 0 || time == NO_ALARM) am.cancel(pendingIntent); else if (time > DateUtilities.now()) { if (Constants.DEBUG) Log.e("Astrid", "Alarm (" + taskId + ", " + type + ") set for " + new Date(time)); am.set(AlarmManager.RTC_WAKEUP, time, pendingIntent); } }
public void testAM(String index, int hour, int minute) { try { long atime = System.currentTimeMillis(); Calendar curTime = Calendar.getInstance(); curTime.set(Calendar.HOUR_OF_DAY, hour); curTime.set(Calendar.MINUTE, minute); curTime.set(Calendar.SECOND, 0); curTime.set(Calendar.MILLISECOND, 0); long btime = curTime.getTimeInMillis(); long triggerTime = btime; if (atime > btime) triggerTime += 1000 * 60 * 60 * 24; Intent intentMyService; intentMyService = new Intent(index); AlarmManager am = (AlarmManager) context.getSystemService(context.ALARM_SERVICE); PendingIntent sender = PendingIntent.getBroadcast(context, 0, intentMyService, 0); // 서비스 시작 am.set(AlarmManager.RTC, triggerTime, sender); } catch (Exception e) { Log.d("MpMainActivity", e.getMessage() + ""); e.printStackTrace(); } }
/** 5分钟后开启注册的与参数匹配的闹铃服务 */ public void onStartService() { intent = new Intent(context, AlarmReceiver.class); intent.setAction(AlarmAction); intent.putExtra("ringStr", ringStr); intent.putExtra("medd_name", name); intent.putExtra("medd_num", num); intent.putExtra("medd_unit", unit); System.out.println( "ringStr=" + ringStr + "//" + "medd_name=" + name + "//" + "medd_num=" + num + "//" + "medd_unit=" + unit); pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0); int type = AlarmManager.RTC_WAKEUP; alarmManager.set(type, currentTime + 5 * 60 * 1000, pendingIntent); System.out.println("5分钟服务开启 "); }
public static void setAlarm(Context context) { SharedPreferences prefs = AnonymousStats.getPreferences(context); if (prefs.contains(AnonymousStats.ANONYMOUS_OPT_IN)) { migrate(context, prefs); } if (!Utilities.isStatsCollectionEnabled(context)) { initiateOptOut(context); return; } long lastSynced = prefs.getLong(AnonymousStats.ANONYMOUS_LAST_CHECKED, 0); if (lastSynced == 0) { launchService(context, true); // service will reschedule the next alarm return; } long millisFromNow = (lastSynced + UPDATE_INTERVAL) - System.currentTimeMillis(); Intent intent = new Intent(ACTION_LAUNCH_SERVICE); intent.setClass(context, ReportingServiceManager.class); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.set( AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + millisFromNow, PendingIntent.getBroadcast(context, 0, intent, 0)); Log.d(TAG, "Next sync attempt in : " + (millisFromNow / MILLIS_PER_HOUR) + " hours"); }
public static void scheduleTrainScheduleRequest( Context context, AlarmManager alarmManager, int munitesToNextExecute) { alarmManager.set( AlarmManager.RTC, System.currentTimeMillis() + munitesToNextExecute * 60 * 1000, createBroadcastPI(context, createIntent(context, TRAIN_SCHEDULE_REQUEST))); }
public void rescheduleNotificationSync(boolean force) { AlarmManager alarmMgr = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); long nexttime; long current_time = System.currentTimeMillis(); long last_sync_time = orm.getNotificationLastTime(); long donespan = (current_time - last_sync_time); long left_time = Long.valueOf(orm.getNotificationInterval()) * sync_period - donespan; if (donespan < 0 || left_time <= 0) { long waittime = 1; for (int i = 0; i < nErrorCount && i < 10; i++) { waittime = waittime * 2; } nexttime = System.currentTimeMillis() + 1 * 60 * 1000 * waittime; } else { nexttime = System.currentTimeMillis() + left_time; } if (force == true) { nexttime = System.currentTimeMillis() + 1 * 60 * 1000; } if (SNSService.TEST_LOOP) { nexttime = System.currentTimeMillis() + 1 * 60 * 1000; } Intent i = new Intent(); i.setClassName("oms.sns.facebook", SERVICE); i.setAction(ACTION); PendingIntent phonebookpi = PendingIntent.getService( mContext.getApplicationContext(), 0, i, PendingIntent.FLAG_CANCEL_CURRENT); alarmMgr.set(AlarmManager.RTC_WAKEUP, nexttime, phonebookpi); }
public static void setReminder( Context context, long id, String title, long dueDate, long listId, long reminderDate, long reminderInterval) { String actionName = context.getResources().getString(R.string.intent_action_alarm); Intent alarmIntent = new Intent(actionName); alarmIntent.putExtra(NotificationUtils.ID, id); alarmIntent.putExtra(NotificationUtils.TITLE, title); alarmIntent.putExtra(NotificationUtils.DUE_DATE, dueDate); alarmIntent.putExtra(NotificationUtils.LIST_ID, listId); PendingIntent alarmPendingIntent = PendingIntent.getBroadcast(context, getNotificationId(id), alarmIntent, 0); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (reminderInterval > 0) { alarmManager.setRepeating( AlarmManager.RTC_WAKEUP, reminderDate, reminderInterval, alarmPendingIntent); if (Log.LOGV) Log.v("TaskDetailDialog set recurring reminder at " + dueDate); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, reminderDate, alarmPendingIntent); if (Log.LOGV) Log.v("TaskDetailDialog set reminder at " + dueDate); } }
public static void setAlarm(Context context, long millisFromNow) { SharedPreferences prefs = AnonymousStats.getPreferences(context); boolean optedIn = prefs.getBoolean(AnonymousStats.ANONYMOUS_OPT_IN, true); if (!optedIn) { return; } if (millisFromNow <= 0) { long lastSynced = prefs.getLong(AnonymousStats.ANONYMOUS_LAST_CHECKED, 0); if (lastSynced == 0) { // never synced, so let's fake out that the last sync was just now. // this will allow the user tFrame time to opt out before it will start // sending up anonymous stats. lastSynced = System.currentTimeMillis(); prefs.edit().putLong(AnonymousStats.ANONYMOUS_LAST_CHECKED, lastSynced).apply(); Log.d(ReportingService.TAG, "Set alarm for first sync."); } millisFromNow = (lastSynced + UPDATE_INTERVAL) - System.currentTimeMillis(); } Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION); intent.setClass(context, ReportingServiceManager.class); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.set( AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + millisFromNow, PendingIntent.getBroadcast(context, 0, intent, 0)); Log.d( ReportingService.TAG, "Next sync attempt in : " + millisFromNow / MILLIS_PER_HOUR + " hours"); }
private void startNavigating() { if (!mStarted) { if (DEBUG) Log.d(TAG, "startNavigating"); mStarted = true; int positionMode; if (Settings.Secure.getInt( mContext.getContentResolver(), Settings.Secure.ASSISTED_GPS_ENABLED, 1) != 0) { positionMode = GPS_POSITION_MODE_MS_BASED; } else { positionMode = GPS_POSITION_MODE_STANDALONE; } if (!native_start(positionMode, false, 1)) { mStarted = false; Log.e(TAG, "native_start failed in startNavigating()"); return; } // reset SV count to zero updateStatus(LocationProvider.TEMPORARILY_UNAVAILABLE, 0); mFixCount = 0; mFixRequestTime = System.currentTimeMillis(); // set timer to give up if we do not receive a fix within NO_FIX_TIMEOUT // and our fix interval is not short if (mFixInterval >= NO_FIX_TIMEOUT) { mAlarmManager.set( AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + NO_FIX_TIMEOUT * 1000, mTimeoutIntent); } } }
@Override public void processReceivedRecommendations() { displayRecommendations(); if (!ClientAuthentication.getIfRecommendNotifyAdded()) { // add to notify ArrayList<FullTrip> recommendations = Storage.getRecommendations(); int i = 1; for (FullTrip ft : recommendations) { Intent myIntent = new Intent(MainActivity.this, RecommendationAlarmReceiver.class); myIntent.setData(Uri.parse("timer:" + i)); myIntent.putExtra("selectedTrip", ft); PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, myIntent, 0); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // notify the user half an hour before the beginning of the trip am.set(AlarmManager.RTC_WAKEUP, ft.getStartTime().getTime() - 1800000, pendingIntent); ClientAuthentication.setIfRecommendNotifyAdded(true); i++; } } }
public void onClick(View v) { AlarmManager mgr = (AlarmManager) AlarmActivity.this.getSystemService(Context.ALARM_SERVICE); Calendar cal = Calendar.getInstance(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(AlarmActivity.this); int snoozeLength = Integer.parseInt(prefs.getString("snooze_length", "10")); int minute = cal.get(Calendar.MINUTE); minute += snoozeLength; cal.set(Calendar.MINUTE, minute); Intent i = new Intent(AlarmActivity.this, OnAlarmReceiver.class); i.putExtra(OnBootReceiver.ID_EXTRA, "-1"); PendingIntent pendInt = PendingIntent.getBroadcast(AlarmActivity.this, -1, i, 0); mgr.set(mgr.RTC_WAKEUP, cal.getTimeInMillis(), pendInt); // Should add a notification that can dismiss the pending snoozed alarm (id = -1) finish(); }
/** * Sets alert in AlarmManger and StatusBar. This is what will actually launch the alert when the * alarm triggers. * * @param alarm Alarm. * @param atTimeInMillis milliseconds since epoch */ private static void enableAlert(Context context, final Alarm alarm, final long atTimeInMillis) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(ALARM_ALERT_ACTION); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // XXX: This is a slight hack to avoid an exception in the remote // AlarmManagerService process. The AlarmManager adds extra data to // this Intent which causes it to inflate. Since the remote process // does not know about the Alarm class, it throws a // ClassNotFoundException. // // To avoid this, we marshall the data ourselves and then parcel a plain // byte[] array. The AlarmReceiver class knows to build the Alarm // object from the byte[] array. Parcel out = Parcel.obtain(); alarm.writeToParcel(out, 0); out.setDataPosition(0); intent.putExtra(ALARM_RAW_DATA, out.marshall()); PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); am.set(AlarmManager.RTC, atTimeInMillis, sender); // am.set(4, atTimeInMillis, sender); // setStatusBarIcon(context, true); Calendar c = Calendar.getInstance(); c.setTimeInMillis(atTimeInMillis); String timeString = formatDayAndTime(context, c); saveNextAlarm(context, timeString); }
@Override public void run() { try { int warn = refreshData(_mContext); Intent broadcastIntent = new Intent(REFRESH_BROADCAST_MESSAGE); _mContext.sendBroadcast(broadcastIntent); if (warn > 0 && warn >= Preferences.getWarnLevel(_mContext)) { Notifier.showNotification(_mContext, warn); } else if (warn == ITerminal.STATE_OK) Notifier.hideNotification(_mContext, false); long interval = Preferences.getUpdateInterval(_mContext); if (interval == 0) return; AlarmManager alarmManager = (AlarmManager) _mContext.getSystemService(Context.ALARM_SERVICE); Intent startIntent = new Intent(_mContext, StatesReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(_mContext, 0, startIntent, 0); alarmManager.set( AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + interval, pendingIntent); } finally { _mWakeLock.release(); } }
/* * It is not the alarm that matters * but the pending intent. * Even with a repeating alarm for an intent, * if you schedule the same intent again * for one time, the later one takes affect. * * It is as if you are setting the * alarm on an existing intent multiple * times and not the other way around. */ public void alarmIntentPrimacy() { Calendar cal = Utils.getTimeAfterInSecs(30); String s = Utils.getDateTimeString(cal); this.mReportTo.reportBack( tag, "Schdeduling Repeating alarm in 5 sec interval starting at: " + s); // Get an intent to invoke // TestReceiver class Intent intent = new Intent(this.mContext, TestReceiver.class); intent.putExtra("message", "Repeating Alarm"); PendingIntent pi = getDistinctPendingIntent(intent, 0); AlarmManager am = (AlarmManager) this.mContext.getSystemService(Context.ALARM_SERVICE); this.mReportTo.reportBack(tag, "Setting a repeat alarm 5 secs duration"); am.setRepeating( AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 5 * 1000, // 5 secs pi); this.mReportTo.reportBack(tag, "Setting a onetime alarm on the same intent"); am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pi); this.mReportTo.reportBack(tag, "The later alarm, one time one, takes precedence"); }
public void setOnetimeTimer(Context context) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, AlarmBroadcastListener.class); intent.putExtra(ONE_TIME, Boolean.TRUE); PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0); am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), pi); }
private void createMonitorAlarm() { AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(this, MonitoringAlarmReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); // the monitoring alarm will schedule another alarm once it's finished alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), pendingIntent); }
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i(TAG, "onStartCommand"); // @TODO should test if startCommand is from autolaunch on boot -> then if yes, check if // CordovaStepCounter.ACTION_START has really been called or die Log.i(TAG, "- Relaunch service in 1 hour (4.4.2 start_sticky bug ) : "); Intent newServiceIntent = new Intent(this, StepCounterService.class); AlarmManager aManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); PendingIntent stepIntent = PendingIntent.getService( getApplicationContext(), 10, newServiceIntent, PendingIntent.FLAG_UPDATE_CURRENT); // PendingIntent.GetService (ApplicationContext, 10, intent2, PendingIntentFlags.UpdateCurrent); aManager.set( AlarmManager.RTC, java.lang.System.currentTimeMillis() + 1000 * 60 * 60, stepIntent); if (isRunning /* || has no step sensors */) { Log.i(TAG, "Not initialising sensors"); return Service.START_STICKY; } Log.i(TAG, "Initialising sensors"); doInit(); isRunning = true; return Service.START_STICKY; }
private void setUpNewAlarm() { // get todays date Calendar cal = Calendar.getInstance(); // get current month int currentMonth = cal.get(Calendar.MONTH); // move month ahead currentMonth++; // check if has not exceeded threshold of december if (currentMonth > Calendar.DECEMBER) { // alright, reset month to jan and forward year by 1 e.g fro 2013 to 2014 currentMonth = Calendar.JANUARY; // Move year ahead as well cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + 1); } // reset calendar to next month cal.set(Calendar.MONTH, currentMonth); // cal is set, now create new alarm for next month // Set intent to be broadcast for reminder Intent intent = new Intent(getApplicationContext(), OverheadReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast( getApplicationContext(), cal.get(Calendar.DAY_OF_MONTH), intent, PendingIntent.FLAG_UPDATE_CURRENT); // Set AlarmManager to trigger broadcast AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); alarmManager.set(AlarmManager.RTC, cal.getTimeInMillis(), pendingIntent); }
@Override public void onReceive(Context context, Intent intent) { Log.i("WifiO", "RecvTempDisable"); LogWO logg = new LogWO(context); logg.log("WifiOpti Service disabled for 5m"); SharedPreferences sett = context.getSharedPreferences("WifiOpti", 2); SharedPreferences.Editor settEditor = sett.edit(); settEditor.putBoolean("WifiOptiServiced", false); settEditor.putBoolean("WifiOptiTempDisabled", true); settEditor.commit(); // Turn off service Intent serviceIntent = new Intent(context, WifiOptiService.class); context.stopService(serviceIntent); // Schedule restart Intent alarmIntent = new Intent(context, RecvTempResume.class); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(System.currentTimeMillis()); cal.add(Calendar.MINUTE, 5); Log.d("WifiO", " -> " + cal.getTime().toString()); am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent); }
/** * Run the notification service delayed by a minute to display and (re)schedule upcoming episode * alarms. */ 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 void rescheduleFacebookUser(boolean force) { AlarmManager alarmMgr = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); long nexttime; long current_time = System.currentTimeMillis(); long last_update_time = orm.getLastUpdateFriendTime(); long donespan = (current_time - last_update_time); long left_time = getFriendsTimeout() * 1000L - donespan; if (donespan < 0 || left_time <= 0) { long waittime = 1; for (int i = 0; i < nErrorCount && i < 10; i++) { waittime = waittime * 2; } nexttime = System.currentTimeMillis() + 10 * 1000 * waittime; } else { nexttime = System.currentTimeMillis() + left_time; } if (force == true) { nexttime = System.currentTimeMillis() + 10 * 1000; } if (SNSService.TEST_LOOP) { nexttime = System.currentTimeMillis() + 90 * 1000; } Intent i = new Intent(); i.setClassName("com.ast.free", "com.ast.free.service.SNSService"); i.setAction("com.ast.free.intent.action.FACEBOOK_USER"); PendingIntent userpi = PendingIntent.getService( mContext.getApplicationContext(), 0, i, PendingIntent.FLAG_CANCEL_CURRENT); alarmMgr.set(AlarmManager.RTC_WAKEUP, nexttime, userpi); }
private void registerPongTimeout(long wait_time, String id) { pingID = id; pingTimestamp = System.currentTimeMillis(); alarmManager.set( AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + wait_time, timeoutAlarmPendIntent); }