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:pl.zajecia.cw3.MainService.java
/** * Sets the next alarm, based on wakelock options and interval value. *//*from w ww . jav a2 s.c o m*/ private void setNextAlarm() { Intent intent = new Intent(INTENT_ALARM); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); int addType; switch (mIntervalType) { case MainActivity.INTERVAL_SECONDS: addType = Calendar.SECOND; break; case MainActivity.INTERVAL_MINUTES: addType = Calendar.MINUTE; break; case MainActivity.INTERVAL_HOURS: addType = Calendar.HOUR; break; case MainActivity.INTERVAL_DAYS: addType = Calendar.DAY_OF_YEAR; break; default: addType = MainActivity.INTERVAL_HOURS; } Calendar time = Calendar.getInstance(); time.setTimeInMillis(System.currentTimeMillis()); time.add(addType, mIntervalValue); if (mChangeDuringSleep) { mAlarmM.set(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), pendingIntent); } else { mAlarmM.set(AlarmManager.RTC, time.getTimeInMillis(), pendingIntent); } }
From source file:net.vexelon.currencybg.app.ui.activities.MainActivity.java
/** * Starts background currencies update service *//*from w w w .j a v a 2s .co m*/ public void startService() { Intent myIntent = new Intent(MainActivity.this, RateService.class); pendingIntent = PendingIntent.getService(MainActivity.this, 0, myIntent, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.SECOND, 30); long initialStartTimeout = calendar.getTimeInMillis(); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, initialStartTimeout, Defs.NOTIFY_INTERVAL, pendingIntent); }
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:step.StepService.java
private void startAutoAlarm() { //???, ?AutoStarter Intent intent = new Intent(StepService.this, AutoStarter.class); intent.setAction("com.renren.mobile.android.ACTION_AUTOSTARTER"); PendingIntent autoStart = PendingIntent.getBroadcast(StepService.this, 0, intent, 0); //?//from w ww .j a va 2 s . c o m Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.SECOND, 5); AlarmManager alarmManager = (AlarmManager) StepManager.getmContext() .getSystemService(Context.ALARM_SERVICE); alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), autoStart); }
From source file:com.kyloth.serleena.sensors.BackgroundLocationManager.java
private void acquireResources() { context.registerReceiver(this, new IntentFilter("SERLEENA_ALARM")); Intent intentToFire = new Intent("SERLEENA_ALARM"); if (pendingIntent != null) am.cancel(pendingIntent);/*from w w w .j a v a 2s . c o m*/ pendingIntent = PendingIntent.getBroadcast(context, new Random().nextInt(), intentToFire, PendingIntent.FLAG_CANCEL_CURRENT); am.setInexactRepeating(AlarmManager.RTC_WAKEUP, 0, updateInterval * 1000, pendingIntent); }
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();//from w ww . j a v a2 s .c om } 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.njlabs.amrita.aid.news.NewsUpdateService.java
@Override public void onDestroy() { // I want to restart this service again in one hour AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE); alarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (1000 * 60 * 60 * 6), PendingIntent.getService(this, 0, new Intent(this, NewsUpdateService.class), 0)); }
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//from w w w .jav 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.drinviewer.droiddrinviewer.DrinViewerBroadcastReceiver.java
/** * Starts the alarm repeater after a disconnection from a WiFi network. * The alarm is firing request to discover server at regular time interval * //from ww w. j a v a2 s .c o m * @param context The context to use * @return true on success */ private boolean startAlarmRepeater(Context context) { boolean returnValue = false; // Gets the Binder to the DiscoverServerService IBinder b = peekService(context, new Intent(context, DiscoverServerService.class)); DiscoverServerApi discoverServerApi = DiscoverServerApi.Stub.asInterface(b); // start the alarm repeater only if the api exists and the discover process in not running try { if (b != null && discoverServerApi != null && !discoverServerApi.isRunning()) { // Get the alarm manager if (alarmManager == null) alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Instantiate the intent and set its action Intent i = new Intent(context, this.getClass()); i.setAction(context.getResources().getString(R.string.broadcast_startdiscovery)); // send the wifiBroadcastAddress together with the intent i.putExtra("wifiBroadcastAddress", wifiBroadcastAddress); // Get the broadcast PendingIntent pending = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); if (pending != null) { Calendar cal = Calendar.getInstance(); // cancel the alarm alarmManager.cancel(pending); // Run the intent immediately and schedule repeating at fixed time intervals context.sendBroadcast(i); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis() + DroidDrinViewerConstants.DISCOVER_REPEAT_TIME, DroidDrinViewerConstants.DISCOVER_REPEAT_TIME, pending); returnValue = true; } } } catch (RemoteException e) { e.printStackTrace(); returnValue = false; } return returnValue; }
From source file:com.tvs.signaltracker.STService.java
private void UpdateData(boolean fromGPS) { UpdateWiFi();//from w w w.j av a 2 s .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(); } }