List of usage examples for android.app AlarmManager RTC_WAKEUP
int RTC_WAKEUP
To view the source code for android.app AlarmManager RTC_WAKEUP.
Click Source Link
From source file:org.wso2.iot.agent.services.operation.OperationManagerWorkProfile.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override//w w w . j a v a 2 s . com public void restrictAccessToApplications(Operation operation) throws AndroidAgentException { AppRestriction appRestriction = CommonUtils.getAppRestrictionTypeAndList(operation, getResultBuilder(), getContextResources()); if (Constants.AppRestriction.BLACK_LIST.equals(appRestriction.getRestrictionType())) { Intent restrictionIntent = new Intent(getContext(), AppLockService.class); restrictionIntent.setAction(Constants.APP_LOCK_SERVICE); restrictionIntent.putStringArrayListExtra(Constants.AppRestriction.APP_LIST, (ArrayList) appRestriction.getRestrictedList()); PendingIntent pendingIntent = PendingIntent.getService(getContext(), 0, restrictionIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.SECOND, 1); // First time long frequency = 1 * 1000; // In ms alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), frequency, pendingIntent); getContext().startService(restrictionIntent); } else if (Constants.AppRestriction.WHITE_LIST.equals(appRestriction.getRestrictionType())) { ArrayList appList = (ArrayList) appRestriction.getRestrictedList(); JSONArray whiteListApps = new JSONArray(); for (Object appObj : appList) { JSONObject app = new JSONObject(); try { app.put(Constants.AppRestriction.PACKAGE_NAME, appObj.toString()); app.put(Constants.AppRestriction.RESTRICTION_TYPE, Constants.AppRestriction.WHITE_LIST); whiteListApps.put(app); } catch (JSONException e) { operation.setStatus(getContextResources().getString(R.string.operation_value_error)); operation.setOperationResponse("Error in parsing app white-list payload."); getResultBuilder().build(operation); throw new AndroidAgentException("Invalid JSON format for app white-list bundle.", e); } } Preference.putString(getContext(), Constants.AppRestriction.WHITE_LIST_APPS, whiteListApps.toString()); validateInstalledApps(); } operation.setStatus(getContextResources().getString(R.string.operation_value_completed)); getResultBuilder().build(operation); }
From source file:com.marianhello.cordova.bgloc.LocationUpdateService.java
public void resetStationaryAlarm() { alarmManager.cancel(stationaryAlarmPI); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + STATIONARY_TIMEOUT, stationaryAlarmPI); // Millisec * Second * Minute }/*from www. ja v a 2s . com*/
From source file:com.tvs.signaltracker.STService.java
@Override public void onDestroy() { ServiceHandler.removeCallbacks(ReCheck); ServiceHandler.removeCallbacks(ReSendRun); ServiceHandler.removeCallbacks(LightMode); if (CommonHandler.ServiceMode == 2 || CommonHandler.ServiceMode == 4) { Log.i("SignalTracker::STService", "Parando trabalhos"); try {/*from w ww . j a v a 2s . c o m*/ if (mlocManager != null) { mlocManager.removeGpsStatusListener(GPSs); mlocManager.removeUpdates(GPSLocListener); mlocManager.removeUpdates(NetLocListener); } if (Tel != null) Tel.listen(MyListener, PhoneStateListener.LISTEN_NONE); } catch (Exception e) { } ; MyListener = null; Tel = null; mlocManager = null; GPSs = null; GPSLocListener = null; NetLocListener = null; CommonHandler.GPSFix = false; CommonHandler.NumSattelites = 0; CommonHandler.NumConSattelites = 0; try { String ns = Context.NOTIFICATION_SERVICE; NotificationManager nMgr = (NotificationManager) this.getSystemService(ns); nMgr.cancel(NOTIFICATION); } catch (Exception e) { } } Toast.makeText(getApplicationContext(), getResources().getString(R.string.stservicestopped), Toast.LENGTH_LONG).show(); if (!CommonHandler.KillService) { Intent myIntent = new Intent(STService.this, STService.class); PendingIntent pendingIntent = PendingIntent.getService(STService.this, 0, myIntent, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.SECOND, 2); alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent); } CommonHandler.KillService = false; LocalRunning = false; Opened = false; }
From source file:com.android.providers.downloads.DownloadService.java
/** * Update {@link #mDownloads} to match {@link DownloadProvider} state. * Depending on current download state it may enqueue {@link DownloadThread} * instances, request {@link DownloadScanner} scans, update user-visible * notifications, and/or schedule future actions with {@link AlarmManager}. * <p>//w w w .jav a2 s . c o m * Should only be called from {@link #mUpdateThread} as after being * requested through {@link #enqueueUpdate()}. * * @return If there are active tasks being processed, as of the database * snapshot taken in this update. */ private boolean updateLocked() { final long now = mSystemFacade.currentTimeMillis(); boolean isActive = false; long nextActionMillis = Long.MAX_VALUE; final Set<Long> staleIds = Sets.newHashSet(mDownloads.keySet()); final ContentResolver resolver = getContentResolver(); Cursor cursor = null; try { cursor = resolver.query(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, null, null, null, null); final DownloadInfo.Reader reader = new DownloadInfo.Reader(resolver, cursor); final int idColumn = cursor.getColumnIndexOrThrow(Downloads.Impl._ID); while (cursor.moveToNext()) { final long id = cursor.getLong(idColumn); long currentDownloadNextActionMillis = Long.MAX_VALUE; DownloadInfo info = mDownloads.get(id); if (info != null) { updateDownload(reader, info, now); } else { // Check xunlei engine status when create a new task info = insertDownloadLocked(reader, now); } if (info.mDeleted) { // Delete download if requested, but only after cleaning up if (!TextUtils.isEmpty(info.mMediaProviderUri)) { resolver.delete(Uri.parse(info.mMediaProviderUri), null, null); } // if download has been completed, delete xxx, else delete xxx.midownload if (info.mStatus == Downloads.Impl.STATUS_SUCCESS) { if (info.mFileName != null) { deleteFileIfExists(info.mFileName); } } else { if (info.mFileName != null) { deleteFileIfExists(info.mFileName + Helpers.sDownloadingExtension); } } resolver.delete(info.getAllDownloadsUri(), null, null); } else { staleIds.remove(id); // Kick off download task if ready String pkg = TextUtils.isEmpty(info.mPackage) ? sUnknownPackage : info.mPackage; final boolean activeDownload = info.startDownloadIfReady(MyExecutor.getExecutorInstance(pkg)); // Kick off media scan if completed final boolean activeScan = info.startScanIfReady(mScanner); // get current download task's next action millis currentDownloadNextActionMillis = info.nextActionMillis(now); XLConfig.LOGD("Download " + info.mId + ": activeDownload=" + activeDownload + ", activeScan=" + activeScan); isActive |= activeDownload; isActive |= activeScan; // if equals 0, keep download service on. isActive |= (currentDownloadNextActionMillis == 0); } // Keep track of nearest next action nextActionMillis = Math.min(currentDownloadNextActionMillis, nextActionMillis); } } catch (SQLiteDiskIOException e) { XLConfig.LOGD("error when updateLocked: ", e); } catch (Exception e) { XLConfig.LOGD("error when updateLocked: ", e); } finally { if (cursor != null) { cursor.close(); } } // Clean up stale downloads that disappeared for (Long id : staleIds) { deleteDownloadLocked(id); } // Update notifications visible to user mNotifier.updateWith(mDownloads.values()); // Set alarm when next action is in future. It's okay if the service // continues to run in meantime, since it will kick off an update pass. if (nextActionMillis > 0 && nextActionMillis < Long.MAX_VALUE) { XLConfig.LOGD("scheduling start in " + nextActionMillis + "ms"); final Intent intent = new Intent(Constants.ACTION_RETRY); intent.setClass(this, DownloadReceiver.class); mAlarmManager.set(AlarmManager.RTC_WAKEUP, now + nextActionMillis, PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT)); } return isActive; }
From source file:com.notalenthack.blaster.CommandActivity.java
private void startStatusUpdate() { // Setup expiration if we never get a message from the service AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(); intent.setAction(Constants.ACTION_REFRESH_STATUS); PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); // Set repeating updating of status, will need to cancel if activity is gone Calendar cal = Calendar.getInstance(); am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), Constants.UPATE_STATUS_PERIOD * 1000, pi); }
From source file:com.prod.intelligent7.engineautostart.ConnectDaemonService.java
void startRecurringBootAlarm() { if (recurringBootIntent != null) { alarmManager.cancel(recurringBootIntent); //return; }/*from ww w . ja v a2 s .com*/ recurringBootIntent = null; GregorianCalendar gToday = new GregorianCalendar( TimeZone.getTimeZone(getResources().getString(R.string.my_time_zone_en))); if (gToday.get(Calendar.HOUR_OF_DAY) >= 7 && gToday.get(Calendar.HOUR_OF_DAY) < 19) return; String bootParameter = readBootParameter(99); Log.i("ALARM_SET", "got n boot parameters " + (bootParameter == null ? "nothing" : bootParameter)); if (bootParameter == null) return; int idx = bootParameter.indexOf("-"); if (idx < 0) return; long init_wait = Long.parseLong(bootParameter.substring(0, idx)); if (init_wait < 2000) //init_wait=2000; { int ixx = bootParameter.indexOf("-", idx + 1); long on_time = Long.parseLong(bootParameter.substring(idx + 1, ixx)); sendCommand("M5-" + new DecimalFormat("00").format(on_time / 60000)); long off_time = Long.parseLong(bootParameter.substring(ixx + 1)); setRecurringBootAlarm(on_time, off_time); return; } Intent jIntent = new Intent(this, ConnectDaemonService.class); //M1-00 (cool) or M1-01 (warm) jIntent.setAction(ALARM_NBOOT); jIntent.putExtra(ConnectDaemonService.ALARM_DONE, ALARM_NBOOT); jIntent.putExtra(ConnectDaemonService.ALARM_NBOOT, bootParameter.substring(idx + 1)); recurringBootIntent = PendingIntent.getService(this, ++nBootAlarmRequestId % 100 + 200, jIntent, PendingIntent.FLAG_ONE_SHOT); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + init_wait, recurringBootIntent); //alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + init_wait, //on_time + off_time, recurringBootIntent); //Log.i("ALARM_SET", "to start recurring boot in " + init_wait/60000);//+" with interval "+(on_time+off_time)/60000); Log.i("ALARM_SET", "to start recurring boot in " + init_wait / 60000); //startScheduledJobs(); }
From source file:ca.ualberta.cs.drivr.MainActivity.java
private void setNotificationAlarm(Context context) { Log.d("ME", "Alarm setup"); Intent intent = new Intent(getApplicationContext(), NotificationReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0); AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); am.cancel(pendingIntent);//from w ww . ja va 2 s. co m am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000, pendingIntent); Log.d("ME", "Alarm started"); }
From source file:com.googlecode.mindbell.accessors.ContextAccessor.java
/** * Schedule an update status notification for the future. *//*from w w w . j ava 2 s . c om*/ private void scheduleUpdateStatusNotification(long targetTimeMillis, int requestCode, String info) { PendingIntent sender = createRefreshBroadcastIntent(requestCode); AlarmManagerCompat alarmManager = new AlarmManagerCompat(context); alarmManager.cancel(sender); // cancel old alarm, it has either gone away or became obsolete if (prefs.isActive()) { alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, targetTimeMillis, sender); TimeOfDay scheduledTime = new TimeOfDay(targetTimeMillis); Log.d(TAG, "Update status notification scheduled for " + scheduledTime.getLogString() + " (" + info + ")"); } }
From source file:com.marianhello.cordova.bgloc.LocationUpdateService.java
public void startPollingStationaryLocation(long interval) { // proximity-alerts don't seem to work while suspended in latest Android 4.42 (works in 4.03). Have to use AlarmManager to sample // location at regular intervals with a one-shot. stationaryLocationPollingInterval = interval; alarmManager.cancel(stationaryLocationPollingPI); long start = System.currentTimeMillis() + (60 * 1000); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, start, interval, stationaryLocationPollingPI); }//from www. jav a 2 s . com
From source file:edu.cmu.mpcs.dashboard.TagViewer.java
private String alarmSetting(String settingString) { if (settingString.contains("set alarm")) { /** Set Alarm **/ String hour = settingString.substring(settingString.indexOf("#") + 1, settingString.indexOf("*")); String minute = settingString.substring(settingString.indexOf("*") + 1, settingString.indexOf("|")); Log.d("timePicker", hour + ":" + minute); int hr = Integer.parseInt(hour); int min = Integer.parseInt(minute); Log.d("Alarm", "hr:" + hr + "min:" + min); Calendar cal = Calendar.getInstance(); // add minutes to the calendar object ////from ww w. j a v a 2s. c om cal.set(Calendar.HOUR_OF_DAY, hr); cal.set(Calendar.MINUTE, min); cal.set(Calendar.SECOND, 0); // cal.add(Calendar.MINUTE, 1); Intent alarmintent = new Intent(getApplicationContext(), AlarmReceiver.class); alarmintent.putExtra("title", "Alarm for " + hour + ":" + minute); alarmintent.putExtra("note", "Touch to turn off Alarm"); // HELLO_ID is a static variable that must be // initialised at the BEGINNING OF CLASS with 1; PendingIntent sender = PendingIntent.getBroadcast(getApplicationContext(), HELLO_ID, alarmintent, PendingIntent.FLAG_UPDATE_CURRENT | Intent.FILL_IN_DATA); // VERY IMPORTANT TO SET FLAG_UPDATE_CURRENT... // this will send correct extra's informations // to // AlarmReceiver Class // Get the AlarmManager service AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender); Log.i("Alarm", "AlarmSet" + cal.toString()); // /** Auto-sync **/ // // if (!ContentResolver.getMasterSyncAutomatically()) // ContentResolver.setMasterSyncAutomatically(true); // else { // ContentResolver.setMasterSyncAutomatically(false); // } return ("AlarmSet for : " + hour + ":" + min + "\n"); } return (""); }