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:be.ac.ucl.lfsab1509.llncampus.services.AlarmService.java
@Override public void onCreate() { super.onCreate(); // Define the Context here, otherwise no Context before launching the application. LLNCampus.setContext(getApplicationContext()); am = (AlarmManager) LLNCampus.getContext().getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(LLNCampus.getContext(), AlarmService.class); PendingIntent pi = PendingIntent.getBroadcast(LLNCampus.getContext(), 0, i, 0); am.set(AlarmManager.ELAPSED_REALTIME, TIME_TO_REPEAT, pi); }
From source file:com.cssweb.android.base.BaseActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); toolbarClick = new ToolbarClick(); alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(this, AutoReceiver.class); pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); // ParamSetting.getInstance().setIsEnternal(false); // ParamSetting.getInstance().setInterval(20000); ServiceControl sControl = new ServiceControl(this); ServiceControl.startScreenReceiver(); ServiceControl.startHomeReceiver();/*from w w w. j a va2 s. c om*/ listenScreen(); sControl.startTrackService(); }
From source file:es.uva.tel.gte.cardiomanager.main.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.slide_main); // Comprobamos la alarma que nos indica si se ha cerrado o no la aplicacin DBAdapter dbAdapter = new DBAdapter(getApplicationContext()); dbAdapter.open();// w ww .j a va 2 s . c o m boolean alarmUp = isMyServiceRunning(AppService.class); if (alarmUp) { // No se ha cerrado la aplicacin Log.println(Log.ASSERT, "Main Activity", "La alarma estaba activa"); } else { Log.println(Log.ASSERT, "Main Activity", "Activamos alarma"); // Se ha cerrado la aplicacion // Volvemos a poner la alarma Intent intent = new Intent(getApplicationContext(), CheckAlarmsService.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 123456789, intent, PendingIntent.FLAG_UPDATE_CURRENT); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.YEAR, 1); // Alarma a 1 ao, tiempo suficiente Log.println(Log.ASSERT, "Alarm Created", "Alarm Created"); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 1000 * 60, pendingIntent); // Comprobamos ahora cuantos medicamentos no se han tomado startService(intent); } // Instantiate a ViewPager and a PagerAdapter. mPager = (ViewPager) findViewById(R.id.pager); mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); mPager.setAdapter(mPagerAdapter); fManager = getSupportFragmentManager(); Cursor cursor = dbAdapter.fetchAllRows(DBAdapter.TABLE_NAME_POLITICS_ACCEPTED); if (cursor.moveToFirst()) { if (cursor.getInt(1) == 1 && cursor.getInt(2) == 1) { // Accepted } else { // Mostrar dilogo PoliticDialog newFragment = new PoliticDialog(); newFragment.show(fManager, "Tag"); } } else { // Mostrar dilogo PoliticDialog newFragment = new PoliticDialog(); newFragment.show(fManager, "Tag"); } dbAdapter.close(); }
From source file:com.battlelancer.seriesguide.appwidget.ListWidgetProvider.java
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); // update all added list widgets for (int appWidgetId : appWidgetIds) { onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, null); }/*from w ww .j av a 2 s .c o m*/ // set an alarm to update widgets every x mins if the device is awake Intent update = new Intent(UPDATE); PendingIntent pi = PendingIntent.getBroadcast(context, 195, update, 0); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + REPETITION_INTERVAL, REPETITION_INTERVAL, pi); }
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 ww. jav a 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:org.wso2.iot.agent.services.kiosk.KioskAlarmReceiver.java
/** * Generic function to generate alarm to both lock and unlock scenarios. * @param context Context of the application. * @param enableLock Set whether its a lock alarm or unlock alarm. * @param isInitialRun Set if its the initial alarm or not. *///from w ww . j ava 2s. c o m @RequiresApi(api = Build.VERSION_CODES.KITKAT) private void buildAlarm(Context context, boolean enableLock, boolean isInitialRun) { AlarmManager alarmManager; PendingIntent pendingIntent; Calendar calendar; int currentTime; alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (Preference.getBoolean(context, Constants.PreferenceCOSUProfile.ENABLE_LOCKDOWN)) { int freezeTime = Preference.getInt(context, Constants.PreferenceCOSUProfile.FREEZE_TIME); int releaseTime = Preference.getInt(context, Constants.PreferenceCOSUProfile.RELEASE_TIME); Intent receiverIntent = new Intent(context, KioskAlarmReceiver.class); receiverIntent.putExtra(Constants.Operation.ENABLE_LOCK, enableLock); if (!enableLock) { /* if releaseTime is after freezeTime, then needs to set unlock alarm in next day since device operation time extends to next day as well. */ calendar = getCalendar(releaseTime, freezeTime > releaseTime); } else if (isInitialRun) { currentTime = getCurrentTimeInMinutes(); /* if currentTime is larger than freezeTime, that means freeze time of current day is already passed. Therefore need to set alarm in next day. */ calendar = getCalendar(freezeTime, currentTime > freezeTime); } else { /* if releaseTime is larger than freezeTime, that means the next freezeTime comes in next day. Therefore need to set alarm in next day. */ calendar = getCalendar(freezeTime, releaseTime > freezeTime); } pendingIntent = PendingIntent.getBroadcast(context, 55, receiverIntent, PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent); Log.d(TAG, "Build alarm to restrict device to " + freezeTime + ":" + releaseTime); } }
From source file:net.peterkuterna.android.apps.devoxxfrsched.service.CfpSyncManager.java
/** * Cancel a currently installed alarm.//from w w w .j a v a 2s . c om */ public void cancelSyncAlarm() { Log.d(TAG, "Cancelling sync alarm"); final Context context = getContext(); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent localPendingIntent = getAlarmPendingIntent(); am.cancel(localPendingIntent); }
From source file:com.twentyoneechoes.borges.util.Utils.java
public static void scheduleLibraryUpdateService(Context context) { if (isAlarmAlreadySet(context)) return;/* ww w. jav a2s . c om*/ AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, LibraryUpdateService.class); PendingIntent alarmIntent = PendingIntent.getService(context, LIBRARY_UPDATE_REQUEST_CODE, intent, 0); alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, AlarmManager.INTERVAL_HALF_HOUR, AlarmManager.INTERVAL_HALF_HOUR, alarmIntent); }
From source file:com.jtechme.apphub.UpdateService.java
public static void schedule(Context ctx) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); String sint = prefs.getString(Preferences.PREF_UPD_INTERVAL, "0"); int interval = Integer.parseInt(sint); Intent intent = new Intent(ctx, UpdateService.class); PendingIntent pending = PendingIntent.getService(ctx, 0, intent, 0); AlarmManager alarm = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE); alarm.cancel(pending);//from www . j ava 2 s.com if (interval > 0) { alarm.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 5000, AlarmManager.INTERVAL_HOUR, pending); Utils.debugLog(TAG, "Update scheduler alarm set"); } else { Utils.debugLog(TAG, "Update scheduler alarm not set"); } }
From source file:it.gulch.linuxday.android.services.AlarmIntentService.java
@Override public void onCreate() { super.onCreate(); setupServices();/*from w w w. j ava2 s. c o m*/ // Ask for the last unhandled intents to be redelivered if the service dies early. // This ensures we handle all events, in order. setIntentRedelivery(true); alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); }