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.matthewmitchell.peercoin_android_wallet.WalletApplication.java
public void scheduleStartBlockchainService() { final WalletApplication wa = this; this.setOnLoadedCallback(new Runnable() { @Override// w ww. ja va 2 s. c o m public void run() { 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 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); assertTrue(config != null); final AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); final PendingIntent alarmIntent = PendingIntent.getService(wa, 0, new Intent(wa, BlockchainServiceImpl.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.ubikod.capptain.android.sdk.reach.CapptainReachAgent.java
/** * Called when download has been completed. * @param content content.//from w ww. j a v a2s .c o m */ void onDownloadComplete(CapptainReachInteractiveContent content) { /* Cancel alarm */ Intent intent = new Intent(INTENT_ACTION_DOWNLOAD_TIMEOUT); intent.setPackage(mContext.getPackageName()); int requestCode = (int) content.getLocalId(); PendingIntent operation = PendingIntent.getBroadcast(mContext, requestCode, intent, 0); AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(operation); /* Update notification if not too late e.g. notification not yet dismissed */ notifyPendingContent(content); }
From source file:me.cpwc.nibblegram.android.NotificationsController.java
private void scheduleNotificationRepeat() { try {//from w ww . j a v a 2s. c o m AlarmManager alarm = (AlarmManager) ApplicationLoader.applicationContext .getSystemService(Context.ALARM_SERVICE); PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, NotificationRepeat.class), 0); SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); int minutes = preferences.getInt("repeat_messages", 60); if (minutes > 0 && personal_count > 0) { alarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + minutes * 60 * 1000, pintent); } else { alarm.cancel(pintent); } } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:org.telepatch.android.NotificationsController.java
private void scheduleNotificationRepeat() { try {/*from www . j ava 2s . c o m*/ AlarmManager alarm = (AlarmManager) ApplicationLoader.applicationContext .getSystemService(Context.ALARM_SERVICE); PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, NotificationRepeat.class), 0); if (personal_count > 0) { alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 60 * 60 * 1000, pintent); } else { alarm.cancel(pintent); } } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:org.thoughtcrime.SMP.notifications.MessageNotifier.java
private static void scheduleReminder(Context context, MasterSecret masterSecret, int count) { if (count >= TextSecurePreferences.getRepeatAlertsCount(context)) { return;//from w w w . ja v a2 s .co m } AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent alarmIntent = new Intent(ReminderReceiver.REMINDER_ACTION); alarmIntent.putExtra("reminder_count", count); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT); long timeout = TimeUnit.MINUTES.toMillis(2); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeout, pendingIntent); }
From source file:org.adblockplus.android.AdblockPlus.java
/** * Sets Alarm to call updater after specified number of minutes or after one * day if/*www . j a v a2s . c om*/ * minutes are set to 0. * * @param minutes * number of minutes to wait */ public void scheduleUpdater(int minutes) { Calendar updateTime = Calendar.getInstance(); if (minutes == 0) { // Start update checks at 10:00 GMT... updateTime.setTimeZone(TimeZone.getTimeZone("GMT")); updateTime.set(Calendar.HOUR_OF_DAY, 10); updateTime.set(Calendar.MINUTE, 0); // ...next day updateTime.add(Calendar.HOUR_OF_DAY, 24); // Spread out the mass downloading? for 6 hours updateTime.add(Calendar.MINUTE, (int) (Math.random() * 60 * 6)); } else { updateTime.add(Calendar.MINUTE, minutes); } Intent updater = new Intent(this, AlarmReceiver.class); PendingIntent recurringUpdate = PendingIntent.getBroadcast(this, 0, updater, PendingIntent.FLAG_CANCEL_CURRENT); // Set non-waking alarm AlarmManager alarms = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarms.set(AlarmManager.RTC, updateTime.getTimeInMillis(), recurringUpdate); }
From source file:org.pixmob.freemobile.netstat.MonitorService.java
@Override public void onTaskRemoved(Intent rootIntent) { if (prefs.getBoolean(SP_KEY_ENABLE_AUTO_RESTART_SERVICE, false) && Arrays .asList(ANDROID_VERSIONS_ALLOWED_TO_AUTO_RESTART_SERVICE).contains(Build.VERSION.RELEASE)) { // If task was removed, we should launch the service again. if (DEBUG) Log.d(TAG, "onTaskRemoved > setting alarm to restart service [ Kitkat START_STICKY bug ]"); Intent restartService = new Intent(getApplicationContext(), this.getClass()); restartService.setPackage(getPackageName()); PendingIntent restartServicePI = PendingIntent.getService(getApplicationContext(), 1, restartService, PendingIntent.FLAG_ONE_SHOT); AlarmManager alarmService = (AlarmManager) getApplicationContext() .getSystemService(Context.ALARM_SERVICE); alarmService.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 1000, restartServicePI); }//from w ww . ja v a 2 s . com }
From source file:org.sipdroid.sipua.ui.Receiver.java
public static void pos(boolean enable) { if (!PreferenceManager.getDefaultSharedPreferences(mContext) .getBoolean(org.sipdroid.sipua.ui.Settings.PREF_POS, org.sipdroid.sipua.ui.Settings.DEFAULT_POS) || PreferenceManager.getDefaultSharedPreferences(mContext) .getString(org.sipdroid.sipua.ui.Settings.PREF_POSURL, org.sipdroid.sipua.ui.Settings.DEFAULT_POSURL) .length() < 1) {//from w ww. j a va 2 s .c o m if (lm != null && am != null) { pos_gps(false); pos_net(false); lm = null; am = null; } return; } if (lm == null) lm = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); if (am == null) am = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); pos_gps(false); if (enable) { if (call_state == UserAgent.UA_STATE_IDLE && Sipdroid.on(mContext) && PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_POS, org.sipdroid.sipua.ui.Settings.DEFAULT_POS) && PreferenceManager.getDefaultSharedPreferences(mContext) .getString(org.sipdroid.sipua.ui.Settings.PREF_POSURL, org.sipdroid.sipua.ui.Settings.DEFAULT_POSURL) .length() > 0) { Location last = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (System.currentTimeMillis() - loctrydate > GPS_UPDATES && (last == null || System.currentTimeMillis() - last.getTime() > GPS_UPDATES)) { loctrydate = System.currentTimeMillis(); pos_gps(true); pos_net(false); } else if (last != null) Receiver.url("lat=" + last.getLatitude() + "&lon=" + last.getLongitude() + "&rad=" + last.getAccuracy()); pos_net(true); } else pos_net(false); } }
From source file:org.wso2.emm.agent.services.operation.OperationManagerWorkProfile.java
@Override public void restrictAccessToApplications(Operation operation) throws AndroidAgentException { AppRestriction appRestriction = CommonUtils.getAppRestrictionTypeAndList(operation, getResultBuilder(), getContextResources());//from w w w .ja v a 2 s .co m 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); } operation.setStatus(getContextResources().getString(R.string.operation_value_completed)); getResultBuilder().build(operation); }
From source file:com.gpsmobitrack.gpstracker.MenuItems.SettingsPage.java
/** * Background updates show ON or OFF// w w w . j a v a 2s . c o m */ private void showAlert(String Message, String Title, final int alertCode) { final Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_Translucent); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(false); dialog.setContentView(R.layout.alert_dialog_main); final TextView alertTitle = (TextView) dialog.findViewById(R.id.alert_title); final TextView alertMsg = (TextView) dialog.findViewById(R.id.alert_msg); final EditText alertEditTxt = (EditText) dialog.findViewById(R.id.alert_edit_txt); Button okBtn = (Button) dialog.findViewById(R.id.alert_ok_btn); Button cancelBtn = (Button) dialog.findViewById(R.id.alert_cancel_btn); alertTitle.setText(Title); alertMsg.setText(Message); alertEditTxt.setVisibility(View.GONE); if (alertCode == 0 || alertCode == UPDATE_INT || alertCode == 7) { cancelBtn.setVisibility(View.VISIBLE); } else { cancelBtn.setVisibility(View.GONE); } cancelBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); if (alertCode == 7) { backUpdateToggle.setChecked(true); editor.putBoolean(AppConstants.IS_SERVICE_ENABLED_PREF, true); editor.commit(); } } }); okBtn.setOnClickListener(new OnClickListener() { @SuppressWarnings("unused") @Override public void onClick(View v) { dialog.dismiss(); if (alertCode == 3 || alertCode == 4) { session.logoutUser(getActivity()); Intent i = new Intent(getActivity(), Login.class); startActivity(i); getActivity().finish(); } else if (alertCode == 0) { deactivateAcc(); } else if (alertCode == UPDATE_INT) { getActivity().finish(); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("market://details?id=com.gpstracker.pro")); startActivity(intent); } else if (alertCode == 7) { backUpdateToggle.setChecked(false); editor.putBoolean(AppConstants.IS_SERVICE_ENABLED_PREF, false); editor.commit(); AlarmManager alarm = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE); Calendar cal = Calendar.getInstance(); Intent intent2 = new Intent(getActivity(), BackgroundService.class); PendingIntent pintent = PendingIntent.getService(getActivity(), 0, intent2, 0); if (PendingIntent.getService(getActivity(), 0, intent2, PendingIntent.FLAG_NO_CREATE) != null) { alarm.cancel(pintent); } } } }); dialog.show(); }