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:ca.marcmeszaros.papyrus.browser.BooksBrowser.java
/** * Executes the query to loan out the book *///w w w. j a v a2 s . c o m private void loanBook(int mYear, int mMonth, int mDay) { // set the due date Calendar c = Calendar.getInstance(); c.set(mYear, mMonth, mDay); // gets the uri path to the user selected Uri user = loanData.getData(); // gets the user id String id = user.getLastPathSegment(); // prepare the query ContentValues values = new ContentValues(); values.put(PapyrusContentProvider.Loans.FIELD_BOOK_ID, selectedBookID); values.put(PapyrusContentProvider.Loans.FIELD_CONTACT_ID, id); values.put(PapyrusContentProvider.Loans.FIELD_LEND_DATE, System.currentTimeMillis()); values.put(PapyrusContentProvider.Loans.FIELD_DUE_DATE, c.getTimeInMillis()); // insert the entry in the database, and get the new loan id Uri newLoan = resolver.insert(PapyrusContentProvider.Loans.CONTENT_URI, values); int loanID = (int) ContentUris.parseId(newLoan); // Book book = new Book(isbn10, title, author); Loan loan = new Loan(loanID, values.getAsInteger(PapyrusContentProvider.Loans.FIELD_BOOK_ID), values.getAsInteger(PapyrusContentProvider.Loans.FIELD_CONTACT_ID), values.getAsLong(PapyrusContentProvider.Loans.FIELD_LEND_DATE), values.getAsLong(PapyrusContentProvider.Loans.FIELD_DUE_DATE)); // get an alarm manager AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // create the intent for the alarm Intent intent = new Intent(this, AlarmReceiver.class); // put the loan object into the alarm receiver intent.putExtra("loan", loan); // create the pendingIntent to run when the alarm goes off and be handled by a receiver PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); // set the repeating alarm am.set(AlarmManager.RTC, c.getTimeInMillis(), pendingIntent); Toast.makeText(this, getString(R.string.BooksBrowser_toast_loanSuccessful), Toast.LENGTH_LONG).show(); }
From source file:org.onebusaway.android.directions.realtime.RealtimeService.java
private AlarmManager getAlarmManager() { return (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); }
From source file:com.android.settings.cyanogenmod.LtoService.java
private PendingIntent scheduleNextDownload(long lastDownload) { AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(this, LtoService.class); PendingIntent pi = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT); long nextLtoDownload = lastDownload + LongTermOrbits.getDownloadInterval(); am.set(AlarmManager.RTC, nextLtoDownload, pi); return pi;//from www . j av a 2 s.co m }
From source file:org.sufficientlysecure.keychain.service.PassphraseCacheService.java
/** * Executed when service is started by intent */// ww w.ja v a 2 s . c om @Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(TAG, "onStartCommand()"); // register broadcastreceiver registerReceiver(); if (intent != null && intent.getAction() != null) { if (ACTION_PASSPHRASE_CACHE_ADD.equals(intent.getAction())) { long ttl = intent.getLongExtra(EXTRA_TTL, DEFAULT_TTL); long keyId = intent.getLongExtra(EXTRA_KEY_ID, -1); String passphrase = intent.getStringExtra(EXTRA_PASSPHRASE); Log.d(TAG, "Received ACTION_PASSPHRASE_CACHE_ADD intent in onStartCommand() with keyId: " + keyId + ", ttl: " + ttl); // add keyId and passphrase to memory mPassphraseCache.put(keyId, passphrase); if (ttl > 0) { // register new alarm with keyId for this passphrase long triggerTime = new Date().getTime() + (ttl * 1000); AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, triggerTime, buildIntent(this, keyId)); } } else if (ACTION_PASSPHRASE_CACHE_GET.equals(intent.getAction())) { long keyId = intent.getLongExtra(EXTRA_KEY_ID, -1); Messenger messenger = intent.getParcelableExtra(EXTRA_MESSENGER); String passphrase = getCachedPassphraseImpl(keyId); Message msg = Message.obtain(); Bundle bundle = new Bundle(); bundle.putString(EXTRA_PASSPHRASE, passphrase); msg.obj = bundle; try { messenger.send(msg); } catch (RemoteException e) { Log.e(Constants.TAG, "Sending message failed", e); } } else { Log.e(Constants.TAG, "Intent or Intent Action not supported!"); } } return START_STICKY; }
From source file:gov.whitehouse.services.LiveService.java
private void scheduleNextUpdate() { Intent intent = new Intent(this, this.getClass()); PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); long now = System.currentTimeMillis(); int intervalSeconds = getResources().getInteger(R.integer.live_feed_update_interval_seconds); long intervalMillis = intervalSeconds * DateUtils.SECOND_IN_MILLIS; long nextUpdateTimeMillis = now + intervalMillis; AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarmManager.set(AlarmManager.RTC, nextUpdateTimeMillis, pendingIntent); }
From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java
/** * Main initialization of the input method component. * Set up the word separators list/*from w w w. j a v a 2 s . c o m*/ * 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.google.android.gcm.GCMBaseIntentService.java
private void handleRegistration(final Context context, Intent intent) { String registrationId = intent.getStringExtra(EXTRA_REGISTRATION_ID); String error = intent.getStringExtra(EXTRA_ERROR); String unregistered = intent.getStringExtra(EXTRA_UNREGISTERED); Log.d(TAG, "handleRegistration: registrationId = " + registrationId + ", error = " + error + ", unregistered = " + unregistered); // registration succeeded if (registrationId != null) { GCMRegistrar.resetBackoff(context); GCMRegistrar.setRegistrationId(context, registrationId); onRegistered(context, registrationId); return;//from w w w . j a v a 2s .com } // unregistration succeeded if (unregistered != null) { // Remember we are unregistered GCMRegistrar.resetBackoff(context); String oldRegistrationId = GCMRegistrar.clearRegistrationId(context); onUnregistered(context, oldRegistrationId); return; } // last operation (registration or unregistration) returned an error; Log.d(TAG, "Registration error: " + error); // Registration failed if (ERROR_SERVICE_NOT_AVAILABLE.equals(error)) { boolean retry = onRecoverableError(context, error); if (retry) { int backoffTimeMs = GCMRegistrar.getBackoff(context); int nextAttempt = backoffTimeMs / 2 + sRandom.nextInt(backoffTimeMs); Log.d(TAG, "Scheduling registration retry, backoff = " + nextAttempt + " (" + backoffTimeMs + ")"); Intent retryIntent = new Intent(INTENT_FROM_GCM_LIBRARY_RETRY); retryIntent.putExtra(EXTRA_TOKEN, TOKEN); PendingIntent retryPendingIntent = PendingIntent.getBroadcast(context, 0, retryIntent, 0); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + nextAttempt, retryPendingIntent); // Next retry should wait longer. if (backoffTimeMs < MAX_BACKOFF_MS) { GCMRegistrar.setBackoff(context, backoffTimeMs * 2); } } else { Log.d(TAG, "Not retrying failed operation"); } } else { // Unrecoverable error, notify app onError(context, error); } }
From source file:com.android.deskclock.timer.TimerReceiver.java
private void updateNextTimesup(Context context) { TimerObj t = getNextRunningTimer(mTimers, false, Utils.getTimeNow()); long nextTimesup = (t == null) ? -1 : t.getTimesupTime(); int timerId = (t == null) ? -1 : t.mTimerId; Intent intent = new Intent(); intent.setAction(Timers.TIMES_UP);/*from w ww .j a va 2s . co m*/ intent.setClass(context, TimerReceiver.class); // Time-critical, should be foreground intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); if (!mTimers.isEmpty()) { intent.putExtra(Timers.TIMER_INTENT_EXTRA, timerId); } AlarmManager mngr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent p = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); if (t != null) { if (Utils.isKitKatOrLater()) { mngr.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextTimesup, p); } else { mngr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextTimesup, p); } if (Timers.LOGGING) { Log.d(TAG, "Setting times up to " + nextTimesup); } } else { // if no timer is found Pending Intents should be canceled // to keep the internal state consistent with the UI mngr.cancel(p); p.cancel(); if (Timers.LOGGING) { Log.v(TAG, "no next times up"); } } }
From source file:com.actinarium.nagbox.service.NagboxService.java
private void rescheduleAlarm() { AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // Prepare pending intent. Setting, updating, or cancelling the alarm - we need it in either case Intent intent = new Intent(this, NagAlarmReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); long nextTimestamp = NagboxDbOps.getClosestNagTimestamp(mDatabase); if (nextTimestamp == 0) { alarmManager.cancel(pendingIntent); } else {//from w w w . j av a2s.c o m // todo: deal with exact/inexact reminders later if (Build.VERSION.SDK_INT >= 23) { alarmManager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, nextTimestamp, pendingIntent); } else if (Build.VERSION.SDK_INT >= 19) { alarmManager.setWindow(AlarmManager.RTC_WAKEUP, nextTimestamp, ALARM_TOLERANCE, pendingIntent); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, nextTimestamp, pendingIntent); } } }
From source file:ca.zadrox.dota2esportticker.service.UpdateMatchService.java
private void cancelAutoUpdate() { 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); 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);//from w ww . j a v a 2 s. c om am.cancel(uri); }