List of usage examples for android.app AlarmManager INTERVAL_HALF_DAY
long INTERVAL_HALF_DAY
To view the source code for android.app AlarmManager INTERVAL_HALF_DAY.
Click Source Link
From source file:ca.zadrox.dota2esportticker.service.UpdateMatchService.java
private void scheduleAutoUpdates() { if (!PrefUtils.shouldAutoUpdate(this)) { return;/*from w ww.ja va 2 s . c o m*/ } final long currentTime = TimeUtils.getUTCTime(); final Intent updateMatchIntent = new Intent(UpdateMatchService.ACTION_AUTO_UPDATE_MATCHES, null, this, UpdateMatchService.class); final Intent updateResultIntent = new Intent(UpdateMatchService.ACTION_UPDATE_RESULTS, null, this, UpdateMatchService.class); final long matchUpdateTime = currentTime + (60000 * 60 * 12); final long resultUpdateTime = currentTime + (60000 * 60); PendingIntent umi = PendingIntent.getService(this.getApplicationContext(), 0, updateMatchIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent uri = PendingIntent.getService(this.getApplicationContext(), 0, updateResultIntent, PendingIntent.FLAG_UPDATE_CURRENT); final AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); am.cancel(umi); am.cancel(uri); am.setInexactRepeating(AlarmManager.RTC, matchUpdateTime, AlarmManager.INTERVAL_HALF_DAY, umi); am.setInexactRepeating(AlarmManager.RTC, resultUpdateTime, AlarmManager.INTERVAL_HOUR, uri); }
From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java
/** * Main initialization of the input method component. * Set up the word separators list//www . ja v a 2s . com * Initialize the core service * Initialize the colours to be used in highlighting * Initialize the list of autocorrected words * Load the suspect-replacement probability distribution map */ @Override public void onCreate() { super.onCreate(); //get User ID try { Class<?> c = Class.forName("android.os.SystemProperties"); Method get = c.getMethod("get", String.class); userid = (String) get.invoke(c, "ro.serialno"); Log.i("OnCreate", "User id= " + userid); } catch (Exception ignored) { Log.i("OnCreate", "Could not obtain userid"); userid = "xxx"; } Editor e = PreferenceManager.getDefaultSharedPreferences(this).edit(); e.putString("prefUsername", userid); e.commit(); //used for managing injected errors errorMap = new HashMap<Integer, Character>(); mWordSeparators = getResources().getString(R.string.word_separators); mSpecialSeparators = getResources().getString(R.string.special_separators); CoreEngineInitialize.initializeCoreService(getApplicationContext()); initializeCore(); assignColours(); autocorrected_words = new HashMap<String, String>(); try { suspectReplacementDistribution = new JSONObject(loadJSONFromAsset()); } catch (JSONException ex) { // TODO Auto-generated catch block ex.printStackTrace(); } //setup the upload task alarm manager /* * Twice daily, broadcast an event * This will be trapped by our receiver */ Intent alarmIntent = new Intent(this, UploadDataReceiver.class); alarmIntent.putExtra("origin", "alarm"); alarmIntent.putExtra("insert", true); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarmManager.setInexactRepeating(AlarmManager.RTC, Calendar.getInstance().getTimeInMillis(), AlarmManager.INTERVAL_HALF_DAY, pendingIntent); //Log.i("OnCreate", "Alarm set "); }
From source file:com.psiphon3.psiphonlibrary.UpgradeChecker.java
/** * Creates the periodic alarm used to check for updates. Can be called unconditionally; it * handles cases when the alarm is already created. * @param appContext The application context. *///from w w w.j a va 2s .co m private static void createAlarm(Context appContext) { if (!allowedToSelfUpgrade(appContext)) { // Don't waste resources with an alarm if we can't possibly self-upgrade. log(appContext, R.string.upgrade_checker_no_alarm_no_selfupgrading, MyLog.Sensitivity.NOT_SENSITIVE, Log.WARN); return; } Intent intent = new Intent(appContext, UpgradeChecker.class); intent.setAction(ALARM_INTENT_ACTION); boolean alarmExists = (PendingIntent.getBroadcast(appContext, ALARM_INTENT_REQUEST_CODE, intent, PendingIntent.FLAG_NO_CREATE) != null); if (alarmExists) { log(appContext, R.string.upgrade_checker_alarm_exists, MyLog.Sensitivity.NOT_SENSITIVE, Log.WARN); return; } log(appContext, R.string.upgrade_checker_creating_alarm, MyLog.Sensitivity.NOT_SENSITIVE, Log.WARN); PendingIntent alarmIntent = PendingIntent.getBroadcast(appContext, ALARM_INTENT_REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmMgr = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE); alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_FIFTEEN_MINUTES, AlarmManager.INTERVAL_HALF_DAY, alarmIntent); }
From source file:de.schildbach.wallet.WalletApplication.java
public static void scheduleStartBlockchainService(final Context context) { final Configuration config = new Configuration(PreferenceManager.getDefaultSharedPreferences(context)); 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//w w w . j a v a 2 s . co 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) context.getSystemService(Context.ALARM_SERVICE); final PendingIntent alarmIntent = PendingIntent.getService(context, 0, new Intent(context, 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:de.langerhans.wallet.WalletApplication.java
public static void scheduleStartBlockchainService(@Nonnull final Context context) { final Configuration config = new Configuration(PreferenceManager.getDefaultSharedPreferences(context)); 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/*from ww w. j a v a2 s .c om*/ 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) context.getSystemService(Context.ALARM_SERVICE); final Intent startIntent = new Intent(context, AutosyncReceiver.class); startIntent.setAction("de.langerhans.wallet.AUTOSYNC_ACTION"); final PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, startIntent, 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:biz.wiz.android.wallet.WalletApplication.java
public static void scheduleStartBlockchainService(@Nonnull final Context context) { final Configuration config = new Configuration(PreferenceManager.getDefaultSharedPreferences(context)); 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/*from w w w. j a va 2s .c om*/ 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) context.getSystemService(Context.ALARM_SERVICE); final PendingIntent alarmIntent = PendingIntent.getService(context, 0, new Intent(context, 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:org.hopestarter.wallet.WalletApplication.java
public static void scheduleStartBlockchainService(final Context context) { final Configuration config = new Configuration(PreferenceManager.getDefaultSharedPreferences(context), context.getResources());/* w w w . j av a2 s.com*/ 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); final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final PendingIntent alarmIntent = PendingIntent.getService(context, 0, new Intent(context, 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.matthewmitchell.peercoin_android_wallet.WalletApplication.java
public void scheduleStartBlockchainService() { final WalletApplication wa = this; this.setOnLoadedCallback(new Runnable() { @Override// www. ja v a 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:eu.faircode.adblocker.ServiceSinkhole.java
@Override public void onCreate() { Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this)); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // Native init jni_init();/*from w w w. j a va 2 s. c om*/ boolean pcap = prefs.getBoolean("pcap", false); setPcap(pcap, this); prefs.registerOnSharedPreferenceChangeListener(this); Util.setTheme(this); super.onCreate(); HandlerThread commandThread = new HandlerThread(getString(R.string.app_name) + " command"); HandlerThread logThread = new HandlerThread(getString(R.string.app_name) + " log"); HandlerThread statsThread = new HandlerThread(getString(R.string.app_name) + " stats"); commandThread.start(); logThread.start(); statsThread.start(); commandLooper = commandThread.getLooper(); logLooper = logThread.getLooper(); statsLooper = statsThread.getLooper(); commandHandler = new CommandHandler(commandLooper); logHandler = new LogHandler(logLooper); statsHandler = new StatsHandler(statsLooper); // Listen for interactive state changes last_interactive = Util.isInteractive(this); IntentFilter ifInteractive = new IntentFilter(); ifInteractive.addAction(Intent.ACTION_SCREEN_ON); ifInteractive.addAction(Intent.ACTION_SCREEN_OFF); ifInteractive.addAction(ACTION_SCREEN_OFF_DELAYED); registerReceiver(interactiveStateReceiver, ifInteractive); // Listen for power save mode if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !Util.isPlayStoreInstall(this)) { PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); powersaving = pm.isPowerSaveMode(); IntentFilter ifPower = new IntentFilter(); ifPower.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED); registerReceiver(powerSaveReceiver, ifPower); } // Listen for user switches if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { IntentFilter ifUser = new IntentFilter(); ifUser.addAction(Intent.ACTION_USER_BACKGROUND); ifUser.addAction(Intent.ACTION_USER_FOREGROUND); registerReceiver(userReceiver, ifUser); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Listen for idle mode state changes IntentFilter ifIdle = new IntentFilter(); ifIdle.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); registerReceiver(idleStateReceiver, ifIdle); } // Listen for connectivity updates IntentFilter ifConnectivity = new IntentFilter(); ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(connectivityChangedReceiver, ifConnectivity); // Listen for added applications IntentFilter ifPackage = new IntentFilter(); ifPackage.addAction(Intent.ACTION_PACKAGE_ADDED); ifPackage.addDataScheme("package"); registerReceiver(packageAddedReceiver, ifPackage); // Setup house holding Intent alarmIntent = new Intent(this, ServiceSinkhole.class); alarmIntent.setAction(ACTION_HOUSE_HOLDING); PendingIntent pi = PendingIntent.getService(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.setInexactRepeating(AlarmManager.RTC, SystemClock.elapsedRealtime() + 60 * 1000, AlarmManager.INTERVAL_HALF_DAY, pi); }
From source file:com.master.metehan.filtereagle.ServiceSinkhole.java
@Override public void onCreate() { Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this)); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // Native init jni_init();/* w ww. ja va 2 s . c o m*/ boolean pcap = prefs.getBoolean("pcap", false); setPcap(pcap, this); prefs.registerOnSharedPreferenceChangeListener(this); Util.setTheme(this); super.onCreate(); HandlerThread commandThread = new HandlerThread(getString(R.string.app_name) + " command"); HandlerThread logThread = new HandlerThread(getString(R.string.app_name) + " log"); HandlerThread statsThread = new HandlerThread(getString(R.string.app_name) + " stats"); commandThread.start(); logThread.start(); statsThread.start(); commandLooper = commandThread.getLooper(); logLooper = logThread.getLooper(); statsLooper = statsThread.getLooper(); commandHandler = new CommandHandler(commandLooper); logHandler = new LogHandler(logLooper); statsHandler = new StatsHandler(statsLooper); // Listen for interactive state changes last_interactive = Util.isInteractive(this); IntentFilter ifInteractive = new IntentFilter(); ifInteractive.addAction(Intent.ACTION_SCREEN_ON); ifInteractive.addAction(Intent.ACTION_SCREEN_OFF); ifInteractive.addAction(ACTION_SCREEN_OFF_DELAYED); registerReceiver(interactiveStateReceiver, ifInteractive); registeredInteractiveState = true; // Listen for power save mode if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !Util.isPlayStoreInstall(this)) { PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); powersaving = pm.isPowerSaveMode(); IntentFilter ifPower = new IntentFilter(); ifPower.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED); registerReceiver(powerSaveReceiver, ifPower); registeredPowerSave = true; } // Listen for user switches if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { IntentFilter ifUser = new IntentFilter(); ifUser.addAction(Intent.ACTION_USER_BACKGROUND); ifUser.addAction(Intent.ACTION_USER_FOREGROUND); registerReceiver(userReceiver, ifUser); registeredUser = true; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Listen for idle mode state changes IntentFilter ifIdle = new IntentFilter(); ifIdle.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); registerReceiver(idleStateReceiver, ifIdle); registeredIdleState = true; } // Listen for connectivity updates IntentFilter ifConnectivity = new IntentFilter(); ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(connectivityChangedReceiver, ifConnectivity); registeredConnectivityChanged = true; // Listen for added applications IntentFilter ifPackage = new IntentFilter(); ifPackage.addAction(Intent.ACTION_PACKAGE_ADDED); ifPackage.addDataScheme("package"); registerReceiver(packageAddedReceiver, ifPackage); registeredPackageAdded = true; // Setup house holding Intent alarmIntent = new Intent(this, ServiceSinkhole.class); alarmIntent.setAction(ACTION_HOUSE_HOLDING); PendingIntent pi = PendingIntent.getService(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.setInexactRepeating(AlarmManager.RTC, SystemClock.elapsedRealtime() + 60 * 1000, AlarmManager.INTERVAL_HALF_DAY, pi); // Setup broadcast to send url map to server. Set inexact repeating for battery saving. Intent urlIntent = new Intent(this, URLBroadcastReceiver.class); PendingIntent urlPendingIntent = PendingIntent.getBroadcast(this, 0, urlIntent, 0); long frequency = 120 * 1000; // two minute frequency for testing //long frequency = AlarmManager.INTERVAL_DAY; am.setInexactRepeating(AlarmManager.RTC, SystemClock.elapsedRealtime() + 60 * 1000, frequency, urlPendingIntent); }