List of usage examples for android.content Context ALARM_SERVICE
String ALARM_SERVICE
To view the source code for android.content Context ALARM_SERVICE.
Click Source Link
From source file:com.atlas.mars.weatherradar.MainActivity.java
@Override protected void onResume() { super.onResume(); if (forecast == null) { //frLayoutCurrent = (FrameLayout) findViewById(R.id.frLayoutCurrent); forecast = new Forecast(this, forecastLinearLayout); } else if (updateForecastIsNeeded()) { if (forecast != null) { forecast.onRegen();/* www . j a v a 2s. co m*/ } else { // frLayoutCurrent = (FrameLayout) findViewById(R.id.frLayoutCurrent); forecast = new Forecast(this, forecastLinearLayout); } } // startService(new Intent(this, MyService.class)); onCreateMyReceiver(); //setMyTitle(pager.getCurrentItem()); Bundle extras = getIntent().getExtras(); if (pager.getCurrentItem() == 0) { alarmRegenBorispol = (AlarmManager) getSystemService(Context.ALARM_SERVICE); borispolRegenIntent = createIntent("borispolAction", "regetExtras", RegenBorispolBroadCast.class); pIntent3 = PendingIntent.getBroadcast(this, 0, borispolRegenIntent, PendingIntent.FLAG_CANCEL_CURRENT); alarmRegenBorispol.cancel(pIntent3); alarmRegenBorispol.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 2 * 60 * 1000, 2 * 60 * 1000, pIntent3); } Log.d(TAG, "Current page: " + pager.getCurrentItem()); fragmentWeather = new CurrentWeather(); fragmentImageAction = new FragmentImageAction(); fragmentManager = getFragmentManager(); if (!isActivityLeave) { fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.add(R.id.frLayoutCurrent, fragmentWeather); fragmentTransaction.commit(); } ; }
From source file:com.jay.pea.mhealthapp2.utilityClasses.AlarmReceiver.java
public void setOnetimeTimer(Context context) { Log.d(TAG, "set on time timer"); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, AlarmReceiver.class); intent.putExtra(ONE_TIME, Boolean.TRUE); PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0); am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), pi); }
From source file:alaindc.crowdroid.SensorsIntentService.java
public void stub_onSensorChanged(int typeSensor) { if (typeSensor < 0) return;/*from w w w. j a v a 2s .co m*/ float value, minf, maxf; switch (typeSensor) { case Sensor.TYPE_AMBIENT_TEMPERATURE: minf = -20; maxf = 42; break; case Sensor.TYPE_PRESSURE: // https://it.wikipedia.org/wiki/Pressione_atmosferica minf = 870; maxf = 1085; break; case Sensor.TYPE_RELATIVE_HUMIDITY: minf = 30; maxf = 100; break; default: minf = 0; maxf = 0; break; } value = random.nextFloat() * (maxf - minf) + minf; int index = Constants.getIndexAlarmForSensor(typeSensor); SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putString(Constants.PREF_SENSOR_ + typeSensor, Float.toString(value)); editor.commit(); // Update view Intent senseintent = new Intent(Constants.INTENT_UPDATE_SENSORS); senseintent.putExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA, "Sensor " + Constants.getNameOfSensor(typeSensor) + " value: " + Float.toString(value)); LocalBroadcastManager.getInstance(this).sendBroadcast(senseintent); // Set the alarm random alarmMgr = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); Intent intentAlarm = new Intent(getApplicationContext(), SensorsIntentService.class); intentAlarm.setAction(Constants.INTENT_STUB_SENSOR_CHANGED + typeSensor); intentAlarm.putExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, typeSensor); alarmIntent = PendingIntent.getService(getApplicationContext(), 0, intentAlarm, 0); // TODO Set timeout time from server indications int seconds = random.nextInt(50) + 10; // 10/60 sec alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + seconds * 1000, alarmIntent); }
From source file:de.schildbach.wallet.service.BlockchainService.java
public static void scheduleStart(final WalletApplication application) { final Configuration config = application.getConfiguration(); final long lastUsedAgo = config.getLastUsedAgo(); // apply some backoff final long alarmInterval; if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_JUST_MS) alarmInterval = AlarmManager.INTERVAL_FIFTEEN_MINUTES; else if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_RECENTLY_MS) alarmInterval = AlarmManager.INTERVAL_HALF_DAY; else/*ww w.j a v a2 s .c o m*/ alarmInterval = AlarmManager.INTERVAL_DAY; log.info("last used {} minutes ago, rescheduling blockchain sync in roughly {} minutes", lastUsedAgo / DateUtils.MINUTE_IN_MILLIS, alarmInterval / DateUtils.MINUTE_IN_MILLIS); final AlarmManager alarmManager = (AlarmManager) application.getSystemService(Context.ALARM_SERVICE); final PendingIntent alarmIntent = PendingIntent.getService(application, 0, new Intent(application, BlockchainService.class), 0); alarmManager.cancel(alarmIntent); // workaround for no inexact set() before KitKat final long now = System.currentTimeMillis(); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, now + alarmInterval, AlarmManager.INTERVAL_DAY, alarmIntent); }
From source file:com.wizardsofm.deskclock.data.TimerNotificationBuilderPreN.java
@Override public Notification build(Context context, NotificationModel nm, List<Timer> unexpired) { final Timer timer = unexpired.get(0); final long remainingTime = timer.getRemainingTime(); // Generate some descriptive text, a title, and some actions based on timer states. final String contentText; final String contentTitle; @DrawableRes//from w ww. j a v a 2 s . c om int firstActionIconId, secondActionIconId = 0; @StringRes int firstActionTitleId, secondActionTitleId = 0; Intent firstActionIntent, secondActionIntent = null; if (unexpired.size() == 1) { contentText = formatElapsedTimeUntilExpiry(context, remainingTime); if (timer.isRunning()) { // Single timer is running. if (TextUtils.isEmpty(timer.getLabel())) { contentTitle = context.getString(com.wizardsofm.deskclock.R.string.timer_notification_label); } else { contentTitle = timer.getLabel(); } firstActionIconId = com.wizardsofm.deskclock.R.drawable.ic_pause_24dp; firstActionTitleId = com.wizardsofm.deskclock.R.string.timer_pause; firstActionIntent = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); secondActionIconId = com.wizardsofm.deskclock.R.drawable.ic_add_24dp; secondActionTitleId = com.wizardsofm.deskclock.R.string.timer_plus_1_min; secondActionIntent = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_ADD_MINUTE_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); } else { // Single timer is paused. contentTitle = context.getString(com.wizardsofm.deskclock.R.string.timer_paused); firstActionIconId = com.wizardsofm.deskclock.R.drawable.ic_start_24dp; firstActionTitleId = com.wizardsofm.deskclock.R.string.sw_resume_button; firstActionIntent = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_START_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); secondActionIconId = com.wizardsofm.deskclock.R.drawable.ic_reset_24dp; secondActionTitleId = com.wizardsofm.deskclock.R.string.sw_reset_button; secondActionIntent = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_RESET_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); } } else { if (timer.isRunning()) { // At least one timer is running. final String timeRemaining = formatElapsedTimeUntilExpiry(context, remainingTime); contentText = context.getString(com.wizardsofm.deskclock.R.string.next_timer_notif, timeRemaining); contentTitle = context.getString(com.wizardsofm.deskclock.R.string.timers_in_use, unexpired.size()); } else { // All timers are paused. contentText = context.getString(com.wizardsofm.deskclock.R.string.all_timers_stopped_notif); contentTitle = context.getString(com.wizardsofm.deskclock.R.string.timers_stopped, unexpired.size()); } firstActionIconId = com.wizardsofm.deskclock.R.drawable.ic_reset_24dp; firstActionTitleId = com.wizardsofm.deskclock.R.string.timer_reset_all; firstActionIntent = TimerService.createResetUnexpiredTimersIntent(context); } // Intent to load the app and show the timer when the notification is tapped. final Intent showApp = new Intent(context, HandleDeskClockApiCalls.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_TIMERS) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, com.wizardsofm.deskclock.R.string.label_notification); final PendingIntent pendingShowApp = PendingIntent.getActivity(context, 0, showApp, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setOngoing(true) .setLocalOnly(true).setShowWhen(false).setAutoCancel(false).setContentText(contentText) .setContentTitle(contentTitle).setContentIntent(pendingShowApp) .setSmallIcon(com.wizardsofm.deskclock.R.drawable.stat_notify_timer) .setPriority(NotificationCompat.PRIORITY_HIGH).setCategory(NotificationCompat.CATEGORY_ALARM) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setColor(ContextCompat.getColor(context, com.wizardsofm.deskclock.R.color.default_background)); final PendingIntent action1 = Utils.pendingServiceIntent(context, firstActionIntent); final String action1Title = context.getString(firstActionTitleId); builder.addAction(firstActionIconId, action1Title, action1); if (secondActionIntent != null) { final PendingIntent action2 = Utils.pendingServiceIntent(context, secondActionIntent); final String action2Title = context.getString(secondActionTitleId); builder.addAction(secondActionIconId, action2Title, action2); } final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final Intent updateNotification = TimerService.createUpdateNotificationIntent(context); if (timer.isRunning() && remainingTime > MINUTE_IN_MILLIS) { // Schedule a callback to update the time-sensitive information of the running timer. final PendingIntent pi = PendingIntent.getService(context, 0, updateNotification, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); final long nextMinuteChange = remainingTime % MINUTE_IN_MILLIS; final long triggerTime = SystemClock.elapsedRealtime() + nextMinuteChange; TimerModel.schedulePendingIntent(am, triggerTime, pi); } else { // Cancel the update notification callback. final PendingIntent pi = PendingIntent.getService(context, 0, updateNotification, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_NO_CREATE); if (pi != null) { am.cancel(pi); pi.cancel(); } } return builder.build(); }
From source file:com.sean.takeastand.alarmprocess.ScheduledRepeatingAlarm.java
private void setAlarm(long triggerTime) { Calendar nextAlarmTime = Calendar.getInstance(); nextAlarmTime.add(Calendar.MINUTE, mCurrentAlarmSchedule.getFrequency()); if ((mCurrentAlarmSchedule.getEndTime()).before(nextAlarmTime)) { Utils.setRunningScheduledAlarm(mContext, -1); Log.i(TAG, mContext.getString(R.string.alarm_day_over)); Toast.makeText(mContext, "Scheduled reminders over", Toast.LENGTH_LONG).show(); Utils.setImageStatus(mContext, Constants.NO_ALARM_RUNNING); cancelAlarm();/*from w w w. j a v a 2s . c o m*/ endSessionAnalytics(); } else { PendingIntent pendingIntent = createPendingIntent(mContext, mCurrentAlarmSchedule); AlarmManager am = ((AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE)); am.set(AlarmManager.ELAPSED_REALTIME, triggerTime, pendingIntent); Utils.setRunningScheduledAlarm(mContext, mCurrentAlarmSchedule.getUID()); } }
From source file:am.roadpolice.roadpolice.alarm.AlarmReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (context == null || intent == null) { Logger.error("AlarmReceiver", "onReceive(Context " + (context == null ? "null," : ",") + " Intent " + (intent == null ? "null)" : ")")); return;/*from w w w . j ava 2s . c o m*/ } // Set Context mContext = context; // Get shared preferences. SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); // Check internet availability and only in that case start actions. final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); final boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); final String action = intent.getAction(); // Catch Network change state. if (!TextUtils.isEmpty(action) && action.equals("android.net.conn.CONNECTIVITY_CHANGE")) { // If internet connection established if (isConnected) { // If didn't missed last update of data due to network issues do nothing, // otherwise proceed with data updating. final boolean missUpdateDueToNetworkIssue = sp .getBoolean(MainActivity.MISS_UPDATE_DUE_TO_NETWORK_ISSUE, false); if (!missUpdateDueToNetworkIssue) return; } // If user switch off Internet connection do not proceed. else return; } // Check Boot state. else if (!TextUtils.isEmpty(action) && action.equals("android.intent.action.BOOT_COMPLETED")) { // Get stored alarm time. final long nextAlarmTime = PreferenceUtils.getDataLong(context, PreferenceUtils.KEY_ALERT_TIME_IN_MILLIS, -1); if (nextAlarmTime != -1) { // Set new alarm, as after reboot alarm was switched off. if (mAlarmManager == null) mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent alarmIntent = new Intent(context, AlarmReceiver.class); if (mAlarmIntent == null) mAlarmIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0); // Enable boot receiver ComponentName receiver = new ComponentName(context, AlarmReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); final int ui = DialogSettings.getUpdateInterval(context); AlarmType type = ui == DialogSettings.DAILY ? AlarmType.DAILY : ui == DialogSettings.WEEKLY ? AlarmType.WEEKLY : AlarmType.MONTHLY; mAlarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, nextAlarmTime, type.getValue(), mAlarmIntent); } return; } // When alarm rise we appears in the block below. else { Logger.beep(); Logger.beep(); Logger.beep(); // Calculating next alarm time. final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); final int updateInterval = DialogSettings.getUpdateInterval(context); if (updateInterval == DialogSettings.DAILY) calendar.add(Calendar.DATE, 1); else if (updateInterval == DialogSettings.WEEKLY) calendar.add(Calendar.DATE, 7); else if (updateInterval == DialogSettings.MONTHLY) calendar.add(Calendar.MONTH, 1); else Logger.error("AlarmReceiver", "Unknown Update Interval."); // Next alarm time. final long nextAlarmTimeInMillis = calendar.getTimeInMillis(); // Store next alarm time for further use. PreferenceUtils.storeDataLong(context, PreferenceUtils.KEY_ALERT_TIME_IN_MILLIS, nextAlarmTimeInMillis); } if (!isConnected) { Logger.debug("AlarmReceiver", "No Internet connection, while receiving Alarm message"); // If no internet connecting schedule data update, as soon // as internet connection will be available. SharedPreferences.Editor ed = sp.edit(); ed.putBoolean(MainActivity.MISS_UPDATE_DUE_TO_NETWORK_ISSUE, true); ed.apply(); return; } final String cerNum = sp.getString(MainActivity.CER_NUMBER, MainActivity.EMPTY_STRING); final String regNum = sp.getString(MainActivity.REG_NUMBER, MainActivity.EMPTY_STRING); final boolean login = sp.getBoolean(MainActivity.AUTO_LOGIN, false); if (!login) { // If no auto login user detected. Logger.debug("AlarmReceiver", "Why we enter this case if no auto login users detected?"); // Remove alarm. AlarmReceiver.createAlarm(context, AlarmReceiver.AlarmType.NONE); return; } if (TextUtils.isEmpty(cerNum) || TextUtils.isEmpty(regNum)) { Logger.debug("AlarmReceiver", "Why we enter this case if both data are null or empty?"); // Remove alarm. AlarmReceiver.createAlarm(context, AlarmReceiver.AlarmType.NONE); // Remove auto login. SharedPreferences.Editor ed = sp.edit(); ed.putBoolean(MainActivity.AUTO_LOGIN, false); ed.apply(); return; } // Start downloading data from internet. Submitter submitter = new Submitter(cerNum, regNum, this); submitter.executeOnExecutor(Executors.newSingleThreadExecutor()); }
From source file:org.leopub.mat.service.MessageService.java
public static void cancelUpdate(Context context) { Intent i = new Intent(context, MessageService.class); PendingIntent pi = PendingIntent.getService(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(pi);/*from w ww.ja v a 2s . co m*/ pi.cancel(); }
From source file:com.tvs.signaltracker.STService.java
private void UpdateData(boolean fromGPS) { UpdateWiFi();/*from www. ja v a 2s . c o m*/ if (CommonHandler.Signal > -1 & CommonHandler.Signal <= 31 & !CommonHandler.Operator.trim().isEmpty()) { if (Utils.isBetterLocation(CommonHandler.GPSLocation, CommonHandler.NetLocation)) CommonHandler.AddSignal(CommonHandler.GPSLocation.getLatitude(), CommonHandler.GPSLocation.getLongitude(), CommonHandler.Signal, CommonHandler.Weight, true); else CommonHandler.AddSignal(CommonHandler.NetLocation.getLatitude(), CommonHandler.NetLocation.getLongitude(), CommonHandler.Signal, 0.2f, false); if ((CommonHandler.ServiceMode == 1 || CommonHandler.ServiceMode == 3) & fromGPS) { // LightModes - dados atualizados. Ento parar o servio e agendar ele pra LightModeTime * 60 Log.i("SignalTracker::LightMode", "Location Acquired, scheduling next search for " + (CommonHandler.LightModeDelayTime * 60) + " seconds ahead."); CommonHandler.KillService = true; StopWorks(); Intent myIntent = new Intent(STService.this, STService.class); PendingIntent pendingIntent = PendingIntent.getService(STService.this, 0, myIntent, 0); AlarmManager alarmManager = (AlarmManager) STService.this.getSystemService(Context.ALARM_SERVICE); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.SECOND, CommonHandler.LightModeDelayTime * 60); alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent); this.stopSelf(); } else if (CommonHandler.ServiceRunning) showServiceNotification(); } }