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:org.videolan.vlc.gui.video.AdvOptionsDialog.java
public static void setSleep(Context context, Calendar time) { AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(VLCApplication.SLEEP_INTENT); PendingIntent sleepPendingIntent = PendingIntent.getBroadcast(VLCApplication.getAppContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); if (time != null) { alarmMgr.set(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), sleepPendingIntent); } else {/* w w w . ja va2 s . c o m*/ alarmMgr.cancel(sleepPendingIntent); } VLCApplication.sPlayerSleepTime = time; }
From source file:com.near.chimerarevo.activities.MainActivity.java
@Override public void onDestroy() { super.onDestroy(); if (ImageLoader.getInstance().isInited()) { ImageLoader.getInstance().clearDiskCache(); ImageLoader.getInstance().clearMemoryCache(); }/*w w w . j ava 2s. c o m*/ if (mHelper != null) mHelper.dispose(); if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("news_search_pref", true)) { Intent intent = new Intent(getApplicationContext(), NewsService.class); PendingIntent pintent = PendingIntent.getService(getApplicationContext(), 0, intent, 0); AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarm.cancel(pintent); long delay; int sel = Integer.parseInt( PreferenceManager.getDefaultSharedPreferences(this).getString("notification_delay_pref", "0")); switch (sel) { case 0: delay = AlarmManager.INTERVAL_FIFTEEN_MINUTES; break; case 1: delay = AlarmManager.INTERVAL_HALF_HOUR; break; case 2: delay = AlarmManager.INTERVAL_HOUR; break; case 3: delay = 2 * AlarmManager.INTERVAL_HOUR; break; case 4: delay = 3 * AlarmManager.INTERVAL_HOUR; break; case 5: delay = 6 * AlarmManager.INTERVAL_HOUR; break; case 6: delay = AlarmManager.INTERVAL_HALF_DAY; break; case 7: delay = AlarmManager.INTERVAL_DAY; break; default: delay = AlarmManager.INTERVAL_HOUR; break; } alarm.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.uptimeMillis(), delay, pintent); } }
From source file:com.google.android.apps.santatracker.SantaNotificationBuilder.java
public static void ScheduleSantaNotification(Context c, long timestamp, int notificationType) { // Only schedule a notification if the time is in the future if (timestamp < System.currentTimeMillis()) { return;/*w w w.ja va2 s . c o m*/ } AlarmManager alarm = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(c, NotificationBroadcastReceiver.class); i.putExtra(NotificationConstants.KEY_NOTIFICATION_ID, NotificationConstants.NOTIFICATION_ID); // Type is "takeoff", "location", etc. i.putExtra(NotificationConstants.KEY_NOTIFICATION_TYPE, notificationType); // Generate unique pending intent PendingIntent pi = PendingIntent.getBroadcast(c, notificationType, i, 0); // Deliver next time the device is woken up alarm.set(AlarmManager.RTC, timestamp, pi); }
From source file:com.mobicage.rpc.http.HttpCommunicator.java
public HttpCommunicator(final MainService mainService, final Context context, final DatabaseManager databaseManager, final Credentials credentials, final ConfigurationProvider cfgProvider, final SafeRunnable onStartStashingHandler, final SafeRunnable onStopStashingHandler, final SDCardLogger sdcardLogger, final boolean wifiOnlySettingEnabled) { T.UI();/*w w w . j a v a 2 s .c o m*/ mMainService = mainService; mCfgProvider = cfgProvider; mFinishedLock = new Object(); mStateMachineLock = new Object(); mStartStashingHandler = onStartStashingHandler; mStopStashingHandler = onStopStashingHandler; mWifiOnlyEnabled = wifiOnlySettingEnabled; mSDCardLogger = sdcardLogger; mAlarmManager = (AlarmManager) mMainService.getSystemService(Context.ALARM_SERVICE); // Create network thread for actual network communication mNetworkWorkerThread = new HandlerThread("rogerthat_net_worker"); mNetworkWorkerThread.start(); final Looper looper = mNetworkWorkerThread.getLooper(); mNetworkHandler = new Handler(looper); mNetworkHandler.post(new SafeRunnable() { @Override protected void safeRun() throws Exception { debugLog("HTTP network thread id is " + android.os.Process.myTid()); } }); final CountDownLatch latch = new CountDownLatch(1); mMainService.postAtFrontOfBIZZHandler(new SafeRunnable() { @Override public void safeRun() { T.BIZZ(); // For simplicity, I want to construct backlog on HTTP thread // This way backlog is 100% on HTTP thread mBacklog = new HttpBacklog(context, databaseManager); latch.countDown(); } }); try { latch.await(); } catch (InterruptedException e) { bugLog(e); } mBase64Username = Base64.encodeBytes(credentials.getUsername().getBytes(), Base64.DONT_BREAK_LINES); mBase64Password = Base64.encodeBytes(credentials.getPassword().getBytes(), Base64.DONT_BREAK_LINES); mMainService.addHighPriorityIntent(HttpCommunicator.INTENT_HTTP_START_OUTGOING_CALLS); if (CloudConstants.USE_GCM_KICK_CHANNEL) { final IntentFilter filter = new IntentFilter(); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); filter.addAction(INTENT_SHOULD_RETRY_COMMUNICATION); mMainService.registerReceiver(mBroadcastReceiver, filter); } }
From source file:com.mobiperf.MeasurementScheduler.java
@Override public void onCreate() { Logger.d("Service onCreate called"); PhoneUtils.setGlobalContext(this.getApplicationContext()); phoneUtils = PhoneUtils.getPhoneUtils(); phoneUtils.registerSignalStrengthListener(); this.checkin = new Checkin(this); this.checkinRetryIntervalSec = Config.MIN_CHECKIN_RETRY_INTERVAL_SEC; this.checkinRetryCnt = 0; this.checkinTask = new CheckinTask(); this.pauseRequested = true; this.stopRequested = false; this.measurementExecutor = Executors.newSingleThreadExecutor(); this.taskQueue = new PriorityBlockingQueue<MeasurementTask>(Config.MAX_TASK_QUEUE_SIZE, new TaskComparator()); this.pendingTasks = new ConcurrentHashMap<MeasurementTask, Future<MeasurementResult>>(); // expect it to be the same size as the queue this.currentSchedule = new Hashtable<String, MeasurementTask>(Config.MAX_TASK_QUEUE_SIZE); this.notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); this.alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); this.resourceCapManager = new ResourceCapManager(Config.DEFAULT_BATTERY_THRESH_PRECENT, this); restoreState();/*from w w w. ja va2 s .c o m*/ // Register activity specific BroadcastReceiver here IntentFilter filter = new IntentFilter(); filter.addAction(UpdateIntent.PREFERENCE_ACTION); filter.addAction(UpdateIntent.MSG_ACTION); filter.addAction(UpdateIntent.CHECKIN_ACTION); filter.addAction(UpdateIntent.CHECKIN_RETRY_ACTION); filter.addAction(UpdateIntent.MEASUREMENT_ACTION); filter.addAction(UpdateIntent.MEASUREMENT_PROGRESS_UPDATE_ACTION); broadcastReceiver = new BroadcastReceiver() { // Handles various broadcast intents. // If traffic is paused by RRCTrafficControl (because a RRC test is // running), we do not perform the checkin, since sending interfering // traffic makes the RRC inference task abort and restart the current // test as the traffic may have altered the phone's RRC state. @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(UpdateIntent.PREFERENCE_ACTION)) { updateFromPreference(); } else if (intent.getAction().equals(UpdateIntent.CHECKIN_ACTION) || intent.getAction().equals(UpdateIntent.CHECKIN_RETRY_ACTION) && !RRCTrafficControl.checkIfPaused()) { Logger.d("Checkin intent received"); handleCheckin(false); } else if (intent.getAction().equals(UpdateIntent.MEASUREMENT_ACTION) && !RRCTrafficControl.checkIfPaused()) { Logger.d("MeasurementIntent intent received"); handleMeasurement(); } else if (intent.getAction().equals(UpdateIntent.MEASUREMENT_PROGRESS_UPDATE_ACTION)) { Logger.d("MeasurementIntent update intent received"); if (intent.getIntExtra(UpdateIntent.PROGRESS_PAYLOAD, Config.INVALID_PROGRESS) == Config.MEASUREMENT_END_PROGRESS) { if (intent.getStringExtra(UpdateIntent.ERROR_STRING_PAYLOAD) != null) { failedMeasurementCnt++; } else { // Process result completedMeasurementCnt++; } if (intent.getStringExtra(UpdateIntent.RESULT_PAYLOAD) != null) { Logger.d("Measurement result intent received"); saveResultToFile(intent.getStringExtra(UpdateIntent.RESULT_PAYLOAD)); } updateResultsConsole(intent); } } else if (intent.getAction().equals(UpdateIntent.MSG_ACTION)) { String msg = intent.getExtras().getString(UpdateIntent.STRING_PAYLOAD); Date now = Calendar.getInstance().getTime(); insertStringToConsole(systemConsole, now + "\n\n" + msg); } } }; this.registerReceiver(broadcastReceiver, filter); // TODO(mdw): Make this a user-selectable option addIconToStatusBar(); }
From source file:com.monkey.entonado.MainActivity.java
/** * OnResume//from w w w . ja v a 2 s . c om * register the broadcast receiver with the intent values to be matched */ @Override protected void onResume() { super.onResume(); registerReceiver(mReceiver, mIntentFilter); CountDownTimer t = new CountDownTimer(1000, 500) { public void onTick(long millisUntilFinished) { } public void onFinish() { if (intentoConectar) { mostrarMensaje(mensajeConexion); intentoConectar = false; } else if (intentoEnviarLista) { String mensaje = ""; boolean entro = false; if (mensajeConexion == null) { mensaje = "Estas desconectado"; } else if (mensajeConexion.equals("desconectado")) { mensaje = "Estas desconectado"; } else if (mensajeConexion.equals("Estas conectado!")) { mensaje = "La lista ha sido enviada"; Intent in = new Intent(MainActivity.this, AlarmReciever.class); PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, 0, in, PendingIntent.FLAG_ONE_SHOT); entro = true; System.out.println("puso alarma"); AlarmManager am = (AlarmManager) MainActivity.this.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1000 * 60, pi); } else { mensaje = mensajeConexion; } if (!entro) mostrarMensaje(mensaje); intentoEnviarLista = false; } } }.start(); }
From source file:nu.yona.app.api.service.ActivityMonitorService.java
private void restartService() { Intent restartServiceIntent = new Intent(getApplicationContext(), this.getClass()); restartServiceIntent.setPackage(getPackageName()); PendingIntent restartServicePendingIntent = PendingIntent.getService(getApplicationContext(), 1, restartServiceIntent, PendingIntent.FLAG_ONE_SHOT); AlarmManager alarmService = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); alarmService.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + AppConstant.ONE_SECOND, restartServicePendingIntent); }
From source file:de.azapps.mirakel.reminders.ReminderAlarm.java
private static void updateAlarms(final Context ctx) { new Thread(new Runnable() { @Override//from w w w . jav a 2 s .c o m public void run() { Log.e(TAG, "update"); alarmManager = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE); // Update the Notifications at midnight final Intent intent = new Intent(ctx, ReminderAlarm.class); intent.setAction(UPDATE_NOTIFICATION); final PendingIntent pendingIntent = PendingIntent.getBroadcast(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); final Calendar triggerCal = new GregorianCalendar(); triggerCal.set(Calendar.HOUR_OF_DAY, 0); triggerCal.set(Calendar.MINUTE, 0); triggerCal.add(Calendar.DAY_OF_MONTH, 1); alarmManager.setRepeating(AlarmManager.RTC, triggerCal.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); // Alarms final List<Task> tasks = Task.getTasksWithReminders(); final Calendar now = new GregorianCalendar(); for (final Pair<Task, PendingIntent> p : activeAlarms) { final Task t = p.first; final Task newTask = Task.get(t.getId()).orNull(); if ((newTask == null) || !newTask.getReminder().isPresent() || newTask.isDone() || newTask.getReminder().get().after(new GregorianCalendar())) { cancelAlarm(ctx, t, newTask, p, p.second); } else if (newTask.getReminder().isPresent()) { if (newTask.getReminder().get().after(now) && !newTask.getRecurringReminder().isPresent()) { closeNotificationFor(ctx, t.getId()); updateAlarm(ctx, newTask); } else if (newTask.getReminder().get().after(now) && newTask.getRecurringReminder().isPresent() && (newTask.getReminder().get() .compareTo(newTask.getRecurringReminder().get() .addRecurring(newTask.getReminder()).orNull()) > 0) && !now.after(newTask.getReminder())) { updateAlarm(ctx, newTask); } else if ((t.getRecurringReminderId() != newTask.getRecurringReminderId()) || t.getRecurringReminder().isPresent()) { if (t.getRecurringReminder().isPresent() && newTask.getRecurringReminder().isPresent()) { if (!t.getRecurringReminder().get().equals(newTask.getRecurringReminder().get())) { updateAlarm(ctx, newTask); cancelAlarm(ctx, t, newTask, p, p.second); } } else if (t.getRecurringReminder().isPresent() != newTask.getRecurringReminder() .isPresent()) { updateAlarm(ctx, newTask); cancelAlarm(ctx, t, newTask, p, p.second); } } else { updateAlarm(ctx, newTask); } } } for (final Task t : tasks) { try { if (!isAlarm(t)) { Log.d(TAG, "add: " + t.getName()); Log.i(TAG, "id " + t.getId()); final PendingIntent p = updateAlarm(ctx, t); activeAlarms.add(new Pair<>(t, p)); } } catch (final NoSuchTaskException e) { Log.wtf(TAG, "Task not found", e); } } } }).start(); }
From source file:com.hhunj.hhudata.ForegroundService.java
private void resetForNewQuery() { networkThread = null;/*w w w .ja v a 2 s . c o m*/ SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); DBUtils dbUtils = new DBUtils(this); long hostid = pref.getLong("hostid", -1); Host h = dbUtils.hostDelegate.getHost(hostid); if (h == null) { h = Host.getdefaultHost(); } m_address = h.getHost(); //m_rss = Constants.getRss(pref); m_port = h.getPort(); m_aquirespan = h.getAquirespan(); m_alamspan = h.getAlamspan(); m_workStartTime = h.getWorkStartTime(); m_workEndTime = h.getWorkEndTime(); m_alarmInWorktime = h.getAlarmInWorktime(); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); }
From source file:com.piusvelte.sonet.SonetService.java
@Override public void onCreate() { super.onCreate(); // handle version changes int currVer = 0; try {/*www. j ava2 s .c o m*/ currVer = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); } SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); if (!sp.contains(getString(R.string.key_version)) || (currVer > sp.getInt(getString(R.string.key_version), 0))) { sp.edit().putInt(getString(R.string.key_version), currVer).commit(); Eidos.requestBackup(this); } mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mConnectivityManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); mSonetCrypto = SonetCrypto.getInstance(getApplicationContext()); // check the instant upload settings startService(Sonet.getPackageIntent(getApplicationContext(), SonetUploader.class)); }