List of usage examples for android.app AlarmManager set
public void set(@AlarmType int type, long triggerAtMillis, PendingIntent operation)
Schedule an alarm.
From source file:com.money.manager.ex.sync.SyncManager.java
/** * Schedule delayed upload via timer.//from w ww . ja v a 2 s. com */ private void scheduleDelayedUpload() { PendingIntent pendingIntent = getPendingIntentForDelayedUpload(); AlarmManager alarm = getAlarmManager(); Timber.d("Setting delayed upload alarm."); // start the sync service after 30 seconds. alarm.set(AlarmManager.RTC_WAKEUP, new MmxDate().getMillis() + 30 * 1000, pendingIntent); }
From source file:org.chromium.chrome.browser.physicalweb.UrlManager.java
private void scheduleClearNotificationAlarm() { PendingIntent pendingIntent = createClearNotificationAlarmIntent(); AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); long time = SystemClock.elapsedRealtime() + STALE_NOTIFICATION_TIMEOUT_MILLIS; alarmManager.set(AlarmManager.ELAPSED_REALTIME, time, pendingIntent); }
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);/*from w w w. ja va2 s .co 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.google.android.apps.muzei.api.MuzeiArtSource.java
private void setUpdateAlarm(long nextTimeMillis) { if (!isEnabled()) { Log.w(TAG, "Source has no subscribers, not actually scheduling next update" + ", id=" + mName); return;/*w ww .ja v a 2s.c o m*/ } if (nextTimeMillis < System.currentTimeMillis()) { Log.w(TAG, "Refusing to schedule next artwork in the past, id=" + mName); return; } AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC, nextTimeMillis, getHandleNextCommandPendingIntent(this)); Log.i(TAG, "Scheduling next artwork (source " + mName + ") at " + new Date(nextTimeMillis)); }
From source file:com.embeddedlog.LightUpDroid.DeskClock.java
private boolean processMenuClick(MenuItem item) { switch (item.getItemId()) { case R.id.menu_item_settings: startActivity(new Intent(DeskClock.this, SettingsActivity.class)); return true; case R.id.menu_item_help: Intent i = item.getIntent();/* w ww .j av a 2 s . com*/ if (i != null) { try { startActivity(i); } catch (ActivityNotFoundException e) { // No activity found to match the intent - ignore } } return true; case R.id.menu_item_night_mode: startActivity(new Intent(DeskClock.this, ScreensaverActivity.class)); case R.id.menu_item_sync_lightuppi: // TODO: update LightUpPiSync to actually sync alarms and then update this bit return true; case R.id.menu_item_push_to_lightuppi: // TODO: update LightUpPiSync to actually push alarms and then update this bit return true; case R.id.menu_item_push_to_phone: // TODO: update LightUpPiSync to actually push alarms and then update this bit String correctString = "android:switcher:" + mViewPager.getId() + ":" + ALARM_TAB_INDEX; new LightUpPiSync(this, correctString).syncPushToPhone(); return true; case R.id.menu_item_reset_db: // Delete the database ContentResolver cr = this.getContentResolver(); cr.call(Uri.parse("content://" + ClockContract.AUTHORITY), "resetAlarmTables", null, null); // Restart the app to repopulate db with default and recreate activities. Intent mStartActivity = new Intent(this, DeskClock.class); int mPendingIntentId = 123456; PendingIntent mPendingIntent = PendingIntent.getActivity(this, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager mgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent); System.exit(0); return true; default: break; } return true; }
From source file:com.numberx.kkmctimer.DeskClock.java
private boolean processMenuClick(MenuItem item) { switch (item.getItemId()) { case R.id.menu_item_settings: startActivity(new Intent(DeskClock.this, SettingsActivity.class)); return true; case R.id.menu_item_help: Intent i = item.getIntent();// ww w.j av a 2 s. co m if (i != null) { try { startActivity(i); } catch (ActivityNotFoundException e) { // No activity found to match the intent - ignore } } return true; case R.id.menu_item_night_mode: startActivity(new Intent(DeskClock.this, ScreensaverActivity.class)); case R.id.menu_item_sync_kkmctimer: // TODO: update KKMCTimerSync to actually sync alarms and then update this bit return true; case R.id.menu_item_push_to_kkmctimer: // TODO: update KKMCTimerSync to actually push alarms and then update this bit return true; case R.id.menu_item_push_to_phone: // TODO: update KKMCTimerSync to actually push alarms and then update this bit String correctString = "android:switcher:" + mViewPager.getId() + ":" + ALARM_TAB_INDEX; new KKMCTimerSync(this, correctString).syncPushToPhone(); return true; case R.id.menu_item_reset_db: // Delete the database ContentResolver cr = this.getContentResolver(); cr.call(Uri.parse("content://" + ClockContract.AUTHORITY), "resetAlarmTables", null, null); // Restart the app to repopulate db with default and recreate activities. Intent mStartActivity = new Intent(this, DeskClock.class); int mPendingIntentId = 123456; PendingIntent mPendingIntent = PendingIntent.getActivity(this, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager mgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent); System.exit(0); return true; default: break; } return true; }
From source file:com.tvs.signaltracker.STService.java
@Override public void onDestroy() { ServiceHandler.removeCallbacks(ReCheck); ServiceHandler.removeCallbacks(ReSendRun); ServiceHandler.removeCallbacks(LightMode); if (CommonHandler.ServiceMode == 2 || CommonHandler.ServiceMode == 4) { Log.i("SignalTracker::STService", "Parando trabalhos"); try {//from w ww . java 2 s . com if (mlocManager != null) { mlocManager.removeGpsStatusListener(GPSs); mlocManager.removeUpdates(GPSLocListener); mlocManager.removeUpdates(NetLocListener); } if (Tel != null) Tel.listen(MyListener, PhoneStateListener.LISTEN_NONE); } catch (Exception e) { } ; MyListener = null; Tel = null; mlocManager = null; GPSs = null; GPSLocListener = null; NetLocListener = null; CommonHandler.GPSFix = false; CommonHandler.NumSattelites = 0; CommonHandler.NumConSattelites = 0; try { String ns = Context.NOTIFICATION_SERVICE; NotificationManager nMgr = (NotificationManager) this.getSystemService(ns); nMgr.cancel(NOTIFICATION); } catch (Exception e) { } } Toast.makeText(getApplicationContext(), getResources().getString(R.string.stservicestopped), Toast.LENGTH_LONG).show(); if (!CommonHandler.KillService) { Intent myIntent = new Intent(STService.this, STService.class); PendingIntent pendingIntent = PendingIntent.getService(STService.this, 0, myIntent, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.SECOND, 2); alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent); } CommonHandler.KillService = false; LocalRunning = false; Opened = false; }
From source file:ca.marcmeszaros.papyrus.browser.BooksBrowser.java
/** * Executes the query to loan out the book *//*from w w w . j a va 2 s. com*/ 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:com.google.samples.apps.sergio.service.SessionAlarmService.java
private void scheduleAlarm(final long sessionStart, final long sessionEnd, final long alarmOffset) { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(NOTIFICATION_ID);/* www.j a va2 s .com*/ final long currentTime = UIUtils.getCurrentTime(this); // If the session is already started, do not schedule system notification. if (currentTime > sessionStart) { LOGD(TAG, "Not scheduling alarm because target time is in the past: " + sessionStart); return; } // By default, sets alarm to go off at 10 minutes before session start time. If alarm // offset is provided, alarm is set to go off by that much time from now. long alarmTime; if (alarmOffset == UNDEFINED_ALARM_OFFSET) { alarmTime = sessionStart - MILLI_TEN_MINUTES; } else { alarmTime = currentTime + alarmOffset; } LOGD(TAG, "Scheduling alarm for " + alarmTime + " = " + (new Date(alarmTime)).toString()); final Intent notifIntent = new Intent(ACTION_NOTIFY_SESSION, null, this, SessionAlarmService.class); // Setting data to ensure intent's uniqueness for different session start times. notifIntent.setData(new Uri.Builder().authority("com.google.samples.apps.sergio") .path(String.valueOf(sessionStart)).build()); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart); LOGD(TAG, "-> Intent extra: session start " + sessionStart); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd); LOGD(TAG, "-> Intent extra: session end " + sessionEnd); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, alarmOffset); LOGD(TAG, "-> Intent extra: session alarm offset " + alarmOffset); PendingIntent pi = PendingIntent.getService(this, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT); final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // Schedule an alarm to be fired to notify user of added sessions are about to begin. LOGD(TAG, "-> Scheduling RTC_WAKEUP alarm at " + alarmTime); am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); }
From source file:com.ncode.android.apps.schedo.service.SessionAlarmService.java
private void scheduleAlarm(final long sessionStart, final long sessionEnd, final long alarmOffset) { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(NOTIFICATION_ID);/* w ww .ja v a 2s . c om*/ final long currentTime = UIUtils.getCurrentTime(this); // If the session is already started, do not schedule system notification. if (currentTime > sessionStart) { LOGD(TAG, "Not scheduling alarm because target time is in the past: " + sessionStart); return; } // By default, sets alarm to go off at 10 minutes before session start time. If alarm // offset is provided, alarm is set to go off by that much time from now. long alarmTime; if (alarmOffset == UNDEFINED_ALARM_OFFSET) { alarmTime = sessionStart - MILLI_TEN_MINUTES; } else { alarmTime = currentTime + alarmOffset; } LOGD(TAG, "Scheduling alarm for " + alarmTime + " = " + (new Date(alarmTime)).toString()); final Intent notifIntent = new Intent(ACTION_NOTIFY_SESSION, null, this, SessionAlarmService.class); // Setting data to ensure intent's uniqueness for different session start times. notifIntent.setData(new Uri.Builder().authority("com.ncode.android.apps.schedo") .path(String.valueOf(sessionStart)).build()); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart); LOGD(TAG, "-> Intent extra: session start " + sessionStart); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd); LOGD(TAG, "-> Intent extra: session end " + sessionEnd); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, alarmOffset); LOGD(TAG, "-> Intent extra: session alarm offset " + alarmOffset); PendingIntent pi = PendingIntent.getService(this, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT); final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // Schedule an alarm to be fired to notify user of added sessions are about to begin. LOGD(TAG, "-> Scheduling RTC_WAKEUP alarm at " + alarmTime); am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); }