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:re.serialout.MainScreen.java
public void setNotificationTimer() { PendingIntent alarmSender = PendingIntent.getBroadcast(this, 0, new Intent(this, AlarmReceiver.class), 0); //Set the alarm to 10 seconds from now Calendar c = Calendar.getInstance(); c.add(Calendar.SECOND, 10);/*w w w. j a v a 2 s . c o m*/ long firstTime = c.getTimeInMillis(); // Schedule the alarm! AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, firstTime, alarmSender); }
From source file:com.pacoapp.paco.triggering.NotificationCreator.java
@SuppressLint("NewApi") private void createAlarmForSnooze(Context context, NotificationHolder notificationHolder) { DateTime alarmTime = new DateTime(notificationHolder.getAlarmTime()); Experiment experiment = experimentProviderUtil .getExperimentByServerId(notificationHolder.getExperimentId()); Integer snoozeTime = notificationHolder.getSnoozeTime(); if (snoozeTime == null) { snoozeTime = DEFAULT_SNOOZE_10_MINUTES; }/*from w ww . j a v a 2 s . com*/ int snoozeMinutes = snoozeTime / MILLIS_IN_MINUTE; DateTime timeoutMinutes = new DateTime(alarmTime).plusMinutes(snoozeMinutes); long snoozeDurationInMillis = timeoutMinutes.getMillis(); Log.info("Creating snooze alarm to resound notification for holder: " + notificationHolder.getId() + ". experiment = " + notificationHolder.getExperimentId() + ". alarmtime = " + new DateTime(alarmTime).toString() + " waking up from snooze in " + timeoutMinutes + " minutes"); Intent ultimateIntent = new Intent(context, AlarmReceiver.class); Uri uri = Uri.withAppendedPath(NotificationHolderColumns.CONTENT_URI, notificationHolder.getId().toString()); ultimateIntent.setData(uri); ultimateIntent.putExtra(NOTIFICATION_ID, notificationHolder.getId().longValue()); ultimateIntent.putExtra(SNOOZE_REPEATER_EXTRA_KEY, true); PendingIntent intent = PendingIntent.getBroadcast(context.getApplicationContext(), 3, ultimateIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(intent); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { alarmManager.setExact(AlarmManager.RTC_WAKEUP, snoozeDurationInMillis, intent); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, snoozeDurationInMillis, intent); } }
From source file:com.dwdesign.tweetings.service.TweetingsService.java
public boolean startAutoRefresh() { stopAutoRefresh();//from w w w . java2s . c om if (mPreferences.getBoolean(PREFERENCE_KEY_AUTO_REFRESH, false)) { final long update_interval = parseInt(mPreferences.getString(PREFERENCE_KEY_REFRESH_INTERVAL, "30")) * 60 * 1000; if (update_interval <= 0) return false; mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + update_interval, update_interval, mPendingRefreshHomeTimelineIntent); mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + update_interval, update_interval, mPendingRefreshMentionsIntent); mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + update_interval, update_interval, mPendingRefreshDirectMessagesIntent); return true; } return false; }
From source file:org.wso2.emm.agent.services.operation.OperationManagerOlderSdk.java
@Override public void restrictAccessToApplications(Operation operation) throws AndroidAgentException { AppRestriction appRestriction = CommonUtils.getAppRestrictionTypeAndList(operation, getResultBuilder(), getContextResources());/* w ww . j a v a 2s . c om*/ String ownershipType = Preference.getString(getContext(), Constants.DEVICE_TYPE); if (Constants.AppRestriction.WHITE_LIST.equals(appRestriction.getRestrictionType())) { if (Constants.OWNERSHIP_COPE.equals(ownershipType)) { List<String> installedAppPackages = CommonUtils.getInstalledAppPackages(getContext()); List<String> toBeHideApps = new ArrayList<>(installedAppPackages); toBeHideApps.removeAll(appRestriction.getRestrictedList()); for (String packageName : toBeHideApps) { CommonUtils.callSystemApp(getContext(), operation.getCode(), "false", packageName); } } } else if (Constants.AppRestriction.BLACK_LIST.equals(appRestriction.getRestrictionType())) { if (Constants.OWNERSHIP_BYOD.equals(ownershipType)) { 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.OWNERSHIP_COPE.equals(ownershipType)) { for (String packageName : appRestriction.getRestrictedList()) { CommonUtils.callSystemApp(getContext(), operation.getCode(), "false", packageName); } } } operation.setStatus(getContextResources().getString(R.string.operation_value_completed)); getResultBuilder().build(operation); }
From source file:com.mobicage.rpc.http.HttpCommunicator.java
private void scheduleRetryCommunication() { final Intent intent = new Intent(INTENT_SHOULD_RETRY_COMMUNICATION); long triggerAtMillis = System.currentTimeMillis() + COMMUNICATION_RETRY_INTERVAL; mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerAtMillis, PendingIntent.getBroadcast(mMainService, 0, intent, 0)); }
From source file:com.songcode.materialnotes.ui.NoteEditActivity.java
public void onClockAlertChanged(long date, boolean set) { /**/*from w w w. ja v a 2 s. c o m*/ * User could set clock to an unsaved note, so before setting the * alert clock, we should save the note first */ if (!mWorkingNote.existInDatabase()) { saveNote(); } if (mWorkingNote.getNoteId() > 0) { Intent intent = new Intent(this, AlarmReceiver.class); intent.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mWorkingNote.getNoteId())); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); AlarmManager alarmManager = ((AlarmManager) getSystemService(ALARM_SERVICE)); mToolbar.setSubtitle(getSubTitle()); if (!set) { alarmManager.cancel(pendingIntent); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, date, pendingIntent); } } else { /** * There is the condition that user has input nothing (the note is * not worthy saving), we have no note id, remind the user that he * should input something */ Log.e(TAG, "Clock alert setting error"); showToast(R.string.error_note_empty_for_clock); } }
From source file:org.wso2.iot.agent.services.operation.OperationManagerBYOD.java
@Override public void restrictAccessToApplications(Operation operation) throws AndroidAgentException { AppRestriction appRestriction = CommonUtils.getAppRestrictionTypeAndList(operation, getResultBuilder(), getContextResources());//from w w w .j ava 2 s.co m String ownershipType = Preference.getString(getContext(), Constants.DEVICE_TYPE); if (Constants.AppRestriction.WHITE_LIST.equals(appRestriction.getRestrictionType())) { //Persisting white-listed app list. JSONArray whiteListApps = new JSONArray(); ArrayList appList = (ArrayList) appRestriction.getRestrictedList(); 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); } } if (Constants.OWNERSHIP_COPE.equals(ownershipType)) { //Removing existing non-white-listed apps. List<String> installedAppPackages = CommonUtils.getInstalledAppPackages(getContext()); List<String> toBeHideApps = new ArrayList<>(installedAppPackages); toBeHideApps.removeAll(appList); for (String packageName : toBeHideApps) { CommonUtils.callSystemApp(getContext(), operation.getCode(), "false", packageName); } } Preference.putString(getContext(), Constants.AppRestriction.WHITE_LIST_APPS, whiteListApps.toString()); } else if (Constants.AppRestriction.BLACK_LIST.equals(appRestriction.getRestrictionType())) { if (Constants.OWNERSHIP_BYOD.equals(ownershipType)) { 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.OWNERSHIP_COPE.equals(ownershipType)) { for (String packageName : appRestriction.getRestrictedList()) { CommonUtils.callSystemApp(getContext(), operation.getCode(), "false", packageName); } } } operation.setStatus(getContextResources().getString(R.string.operation_value_completed)); getResultBuilder().build(operation); }
From source file:com.mobicage.rogerthat.MainService.java
@Override public int onStartCommand(Intent intent, int flags, int startid) { T.UI();//ww w . j ava 2 s .c o m super.onStartCommand(intent, flags, startid); final Bundle extras = intent == null ? null : intent.getExtras(); boolean launchedAtBootTime = false; boolean launchedByBgDataSettingChange = false; boolean launchedByOnCreate = false; boolean launchedByJustRegistered = false; boolean launchedByGCM = false; try { if (extras != null) { launchedAtBootTime = extras.getBoolean(START_INTENT_BOOTTIME_EXTRAS_KEY, false); launchedByBgDataSettingChange = extras .getBoolean(START_INTENT_BACKGROUND_DATA_SETTING_CHANGED_EXTRAS_KEY, false); launchedByOnCreate = extras.getBoolean(START_INTENT_FROM_ONCREATE_KEY, false); launchedByJustRegistered = extras.getBoolean(START_INTENT_JUST_REGISTERED, false); launchedByGCM = extras.getBoolean(START_INTENT_GCM, false); } if (launchedByGCM) { kickHttpCommunication(true, "Incomming GCM"); return START_STICKY; } final boolean isRegisteredInConfig = getRegisteredFromConfig(); L.d("MainService.onStart \n isIntentNull = " + (intent == null) + "\n isRegisteredInConfig = " + isRegisteredInConfig + "\n launchedAtBootTime = " + launchedAtBootTime + "\n launchedByBgDataSettingChange = " + launchedByBgDataSettingChange + "\n launchedByOnCreate = " + launchedByOnCreate + "\n launchedByJustRegistered = " + launchedByJustRegistered); if (launchedByJustRegistered) { setupNetworkProtocol(); final String myEmail = extras == null ? null : extras.getString(START_INTENT_MY_EMAIL); initializeService(myEmail); } if (!isRegisteredInConfig) { L.d("MainService.onStart() - stopping service immediately"); stopSelf(); return START_NOT_STICKY; } // start networking machinery if (CloudConstants.USE_XMPP_KICK_CHANNEL) mXmppKickChannel.start(); getPlugin(SystemPlugin.class).doHeartbeat(); if (CloudConstants.USE_GCM_KICK_CHANNEL) GoogleServicesUtils.registerGCMRegistrationId(this, null); if (launchedByOnCreate) { kickHttpCommunication(true, "We just got started"); } cleanupOldCachedFiles(false); PendingIntent cleanupDownloadsIntent = PendingIntent.getBroadcast(this, 0, new Intent(INTENT_SHOULD_CLEANUP_CACHED_FILES), 0); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + AlarmManager.INTERVAL_DAY * 7, AlarmManager.INTERVAL_DAY * 7, cleanupDownloadsIntent); return START_STICKY; } finally { if (launchedByGCM) { GCMReveiver.completeWakefulIntent(intent); } } }
From source file:com.mobilyzer.MeasurementScheduler.java
/** Set the interval for checkin in seconds */ public synchronized long setCheckinInterval(boolean isForced, long interval) { Logger.d("Scheduler->setCheckinInterval called " + interval); long min = Config.MIN_CHECKIN_INTERVAL_SEC; long max = Config.MAX_CHECKIN_INTERVAL_SEC; if (!isForced && this.checkinIntervalSec != -1) { min = this.batteryThreshold; }/* ww w . j a v a 2 s . c o m*/ // Check whether out of boundary and same with old value if (interval >= min && interval <= max && interval != this.checkinIntervalSec) { this.checkinIntervalSec = interval; Logger.i("Setting checkin interval to " + this.checkinIntervalSec + " seconds"); persistParams(Config.PREF_KEY_CHECKIN_INTERVAL, String.valueOf(this.checkinIntervalSec)); // the new checkin schedule will start // in PAUSE_BETWEEN_CHECKIN_CHANGE_MSEC seconds checkinIntentSender = PendingIntent.getBroadcast(this, 0, new UpdateIntent(UpdateIntent.CHECKIN_ACTION), PendingIntent.FLAG_CANCEL_CURRENT); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + Config.PAUSE_BETWEEN_CHECKIN_CHANGE_MSEC, checkinIntervalSec * 1000, checkinIntentSender); } return this.checkinIntervalSec; }
From source file:com.z3r0byte.magistify.Services.BackgroundService.java
public void setAlarm(Context context) { cancelAlarm(context);//from w w w . j a va 2s .co m AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, BackgroundService.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 60, pendingIntent); }