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:ca.zadrox.dota2esportticker.service.ReminderAlarmService.java
private void scheduleAlarm(final long matchId, final long matchStart) { final long currentTime = TimeUtils.getUTCTime(); LOGD(TAG, "Schedule Alarm"); if (currentTime > matchStart) { LOGD(TAG, "CurrentTime > matchStart"); return;/*from w w w. ja v a 2s.c o m*/ } long alarmTime = matchStart - MILLI_TEN_MINUTES; final Intent notifIntent = new Intent(ACTION_NOTIFY_MATCH, null, this, ReminderAlarmService.class); notifIntent.setData( new Uri.Builder().authority("ca.zadrox.dota2esportticker").path(String.valueOf(matchId)).build()); notifIntent.putExtra(ReminderAlarmService.EXTRA_MATCH_ID, matchId); notifIntent.putExtra(ReminderAlarmService.EXTRA_MATCH_START, matchStart); PendingIntent pi = PendingIntent.getService(this, 0, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT); final AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); }
From source file:org.dodgybits.shuffle.android.server.sync.SyncSchedulingService.java
@Override protected void onHandleIntent(Intent intent) { SyncState state = SyncState.restore(this); state.process(this, intent.getExtras()); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent syncIntent = new Intent(this, SyncReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, syncIntent, PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.set(AlarmManager.RTC_WAKEUP, state.nextScheduledSync, pendingIntent); // Release the wake lock provided by the WakefulBroadcastReceiver WakefulBroadcastReceiver.completeWakefulIntent(intent); }
From source file:net.noio.Reminder.NotificationService.java
@Override protected void onHandleIntent(Intent intent) { Log.v("NotificationService", "Starting NotificationService run"); LinkedList<String[]> list; list = ReminderDB.getReminderTimes(getApplicationContext()); long system_time = System.currentTimeMillis(); // Alarm notification AlarmManager ream = (AlarmManager) getSystemService(Context.ALARM_SERVICE); PendingIntent repi = PendingIntent.getService(this, 6600, intent, 0); ream.set(AlarmManager.RTC_WAKEUP, system_time + 60000, repi); for (int i = 0; i < list.size(); i++) { String[] data = list.get(i); if (data[2].equals("N")) { long delta = Long.parseLong(data[1]) - System.currentTimeMillis(); Log.v("NotificationService", "TIME REMAINING: " + delta); Log.v("NotificationService", "1 HOUR: " + this.ONE_HOUR * 1000); Log.v("NotificationService", "6 HOUR: " + this.SIX_HOUR * 1000); Log.v("NotificationService", "12 HOUR: " + this.TWELVE_HOUR * 1000); Log.v("NotificationService", "24 HOUR: " + this.TWENTYFOUR_HOUR * 1000); Log.v("NotificationService", "In reminder loop"); Intent intent1 = new Intent(this, MainActivity.class); intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (delta < this.ONE_HOUR * 1000) { Log.v("NotificationService", "IN 1"); if (ReminderDB.checkNotify(getApplicationContext(), 1, data[0])) { System.out.println("IN 1b"); intent1.putExtra("string", data[0]); intent1.putExtra("reminder", "One-hour Reminder"); intent1.putExtra("id", Integer.parseInt(10 + ReminderDB.getID(getApplicationContext(), data[0]))); this.Notify(intent1); ReminderDB.disableNotification(getApplicationContext(), 1, data[0]); }/*from w w w .j ava 2s . c om*/ } else if (delta < this.SIX_HOUR * 1000 && delta > this.ONE_HOUR * 1000) { Log.v("NotificationService", "IN 6"); if (ReminderDB.checkNotify(getApplicationContext(), 2, data[0])) { intent1.putExtra("string", data[0]); intent1.putExtra("reminder", "Six-hour Reminder"); intent1.putExtra("id", Integer.parseInt(10 + ReminderDB.getID(getApplicationContext(), data[0]))); this.Notify(intent1); ReminderDB.disableNotification(getApplicationContext(), 2, data[0]); } } else if (delta < this.TWELVE_HOUR * 1000 && delta > this.SIX_HOUR * 1000) { Log.v("NotificationService", "IN 12"); if (ReminderDB.checkNotify(getApplicationContext(), 3, data[0])) { intent1.putExtra("string", data[0]); intent1.putExtra("reminder", "Twelve-hour Reminder"); intent1.putExtra("id", Integer.parseInt(10 + ReminderDB.getID(getApplicationContext(), data[0]))); this.Notify(intent1); ReminderDB.disableNotification(getApplicationContext(), 3, data[0]); } } else if (delta < this.TWENTYFOUR_HOUR * 1000 && delta > this.TWELVE_HOUR * 1000) { Log.v("NotificationService", "IN 24"); if (ReminderDB.checkNotify(getApplicationContext(), 4, data[0])) { intent1.putExtra("string", data[0]); intent1.putExtra("reminder", "Twentyfour-hour Reminder"); intent1.putExtra("id", Integer.parseInt(10 + ReminderDB.getID(getApplicationContext(), data[0]))); this.Notify(intent1); ReminderDB.disableNotification(getApplicationContext(), 4, data[0]); } } } else if (data[2].equals("Y")) { // every minute if (data[3].equals("Y")) { Log.v("NotificationService", "Every minute reminder for " + data[0]); intent.putExtra("string", data[0]); intent.putExtra("reminder", "Every minute reminder"); intent.putExtra("id", Integer.parseInt(10 + ReminderDB.getID(getApplicationContext(), data[0]))); this.Notify(intent); } // every hour if (data[4].equals("Y")) { // fix to be hourly Log.v("NotificationService", "Hourly reminder for " + data[0]); if (this.loopcounter == 60) { this.loopcounter = 0; intent.putExtra("string", data[0]); intent.putExtra("reminder", "Hourly reminder"); intent.putExtra("id", Integer.parseInt(10 + ReminderDB.getID(getApplicationContext(), data[0]))); this.Notify(intent); } this.loopcounter += 1; } } } Log.v("NotificationService", "Ending NotificationService run"); }
From source file:edu.umich.si.inteco.minuku.manager.MinukuNotificationManager.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(TAG, "OnStartCommand"); if (mNotificationManager == null) { mNotificationManager = (android.app.NotificationManager) getSystemService(Service.NOTIFICATION_SERVICE); }//from ww w . j a va 2s. co m AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE); alarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + Constants.PROMPT_SERVICE_REPEAT_MILLISECONDS, PendingIntent.getService(this, 0, new Intent(this, MinukuNotificationManager.class), 0)); Notification note = new Notification.Builder(getBaseContext()) .setContentTitle(Constants.getInstance().getAppName()) .setContentText(Constants.getInstance().getRunningAppDeclaration()) .setSmallIcon(R.drawable.self_reflection).setAutoCancel(false).build(); note.flags |= Notification.FLAG_NO_CLEAR; startForeground(42, note); checkRegisteredNotifications(); return START_STICKY_COMPATIBILITY; }
From source file:com.securecomcode.text.service.KeyCachingService.java
private void startTimeoutIfAppropriate() { boolean timeoutEnabled = TextSecurePreferences.isPassphraseTimeoutEnabled(this); if ((activitiesRunning == 0) && (this.masterSecret != null) && timeoutEnabled && !TextSecurePreferences.isPasswordDisabled(this)) { long timeoutMinutes = TextSecurePreferences.getPassphraseTimeoutInterval(this); long timeoutMillis = timeoutMinutes * 60 * 1000; Log.w("KeyCachingService", "Starting timeout: " + timeoutMillis); AlarmManager alarmManager = (AlarmManager) this.getSystemService(ALARM_SERVICE); alarmManager.cancel(pending);/* ww w.j a v a 2 s . com*/ alarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + timeoutMillis, pending); } }
From source file:com.google.android.apps.iosched.calendar.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);/*from w ww .j a va2 s. c o m*/ final long currentTime = System.currentTimeMillis(); // If the session is already started, do not schedule system notification. if (currentTime > 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 - TEN_MINUTES_MILLIS; } else { alarmTime = currentTime + alarmOffset; } final Intent alarmIntent = new Intent(ACTION_NOTIFY_SESSION, null, this, SessionAlarmService.class); // Setting data to ensure intent's uniqueness for different session start times. alarmIntent.setData(new Uri.Builder().authority(ScheduleContract.CONTENT_AUTHORITY) .path(String.valueOf(sessionStart)).build()); alarmIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart); alarmIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd); alarmIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, alarmOffset); final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // Schedule an alarm to be fired to notify user of added sessions are about to begin. am.set(AlarmManager.RTC_WAKEUP, alarmTime, PendingIntent.getService(this, 0, alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT)); }
From source file:com.conferenceengineer.android.iosched.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 va 2s . c om final long currentTime = UIUtils.getCurrentTime(this); // If the session is already started, do not schedule system notification. if (currentTime > 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; } 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.conferenceengineer.android.iosched") .path(String.valueOf(sessionStart)).build()); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd); notifIntent.putExtra(SessionAlarmService.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. am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); }
From source file:ua.org.gdg.devfest.iosched.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);/*from ww w. j a v a 2 s . com*/ final long currentTime = UIUtils.getCurrentTime(this); // If the session is already started, do not schedule system notification. if (currentTime > 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; } 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("ua.org.gdg.devfest.iosched") .path(String.valueOf(sessionStart)).build()); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd); notifIntent.putExtra(SessionAlarmService.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. am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); }
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:com.njlabs.amrita.aid.landing.Landing.java
@SuppressLint("ShortAlarm") @Override//from w ww.j a v a2 s. c o m public void init(Bundle savedInstanceState) { setupLayout(R.layout.activity_landing, "Amrita Info Desk"); toolbar.setBackgroundColor(getResources().getColor(R.color.white)); setRecentHeaderColor(getResources().getColor(R.color.white)); checkForUpdates(); AccountHeader headerResult = new AccountHeaderBuilder().withActivity(this) .withHeaderBackground(R.drawable.header) .addProfiles(new ProfileDrawerItem().withName("Amrita Info Desk") .withEmail("Version " + BuildConfig.VERSION_NAME).setSelectable(false)) .withSelectionListEnabledForSingleProfile(false).build(); headerResult.getHeaderBackgroundView().setColorFilter(Color.rgb(170, 170, 170), android.graphics.PorterDuff.Mode.MULTIPLY); Drawer result = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withAccountHeader(headerResult) .addDrawerItems( new PrimaryDrawerItem().withName("Home").withIcon(R.drawable.ic_action_home) .withCheckable(false), new PrimaryDrawerItem() .withName("News").withIcon(R.drawable.ic_action_speaker_notes).withCheckable(false), new DividerDrawerItem(), new PrimaryDrawerItem().withName("About the app").withIcon(R.drawable.ic_action_info) .withCheckable(false), new PrimaryDrawerItem().withName("Invite").withIcon(R.drawable.ic_action_info) .withCheckable(false), new PrimaryDrawerItem().withName("Settings").withIcon(R.drawable.ic_action_settings) .withCheckable(false)) .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { @Override public boolean onItemClick(AdapterView<?> parent, View view, int position, long id, IDrawerItem drawerItem) { switch (position) { case 1: startActivity(new Intent(baseContext, NewsActivity.class)); break; case 3: startActivity(new Intent(baseContext, App.class)); break; case 4: Intent intent = new AppInviteInvitation.IntentBuilder("Invite users") .setMessage("Spread the word to fellow Amrititans") .setCallToActionText("Invite").build(); startActivityForResult(intent, 211); break; case 5: startActivity(new Intent(baseContext, SettingsActivity.class)); break; } return false; } }).withCloseOnClick(true).build(); setupGrid(); File aumsCookieFile = new File(getApplicationContext().getFilesDir().getParent() + "/shared_prefs/" + PersistentCookieStore.AUMS_COOKIE_PREFS + ".xml"); if (aumsCookieFile.exists()) { aumsCookieFile.delete(); } File gpmsCookieFile = new File(getApplicationContext().getFilesDir().getParent() + "/shared_prefs/" + PersistentCookieStore.GPMS_COOKIE_PREFS + ".xml"); if (gpmsCookieFile.exists()) { gpmsCookieFile.delete(); } 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)); startService(new Intent(baseContext, NewsUpdateService.class)); }