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:com.adguard.android.service.FilterServiceImpl.java
@Override public void scheduleFiltersUpdate() { Intent alarmIntent = new Intent(AlarmReceiver.UPDATE_FILTER_ACTION); boolean isRunning = PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_NO_CREATE) != null; if (!isRunning) { LOG.info("Starting scheduler of filters updating"); PendingIntent broadcastIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, UPDATE_INITIAL_PERIOD, AlarmManager.INTERVAL_HOUR, broadcastIntent);/*from w ww .j a va2s . co m*/ } else { LOG.info("Filters update is running"); } }
From source file:com.hedgehog.smdb.ActionBarControlScrollViewActivity.java
private void repeat() { BroadcastReceiver receiver = new BroadcastReceiver() { @Override// w w w. j a v a 2 s . c o m public void onReceive(Context context, Intent intent) { showNotification(); } }; this.registerReceiver(receiver, new IntentFilter("TecxiDriverCheckingForConfirmedBids")); PendingIntent pintent = PendingIntent.getBroadcast(this, 0, new Intent("TecxiDriverCheckingForConfirmedBids"), 0); AlarmManager manager = (AlarmManager) (this.getSystemService(Context.ALARM_SERVICE)); manager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 0, 1000 * 60 * 30, pintent); }
From source file:org.chromium.chrome.browser.ntp.ContentSuggestionsNotificationHelper.java
@CalledByNative private static boolean showNotification(int category, String idWithinCategory, String url, String title, String text, Bitmap image, long timeoutAtMillis) { if (findActiveNotification(category, idWithinCategory) != null) return false; // Post notification. Context context = ContextUtils.getApplicationContext(); NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); int nextId = nextNotificationId(); Uri uri = Uri.parse(url);/* w ww . ja v a 2s .co m*/ Intent contentIntent = new Intent(context, OpenUrlReceiver.class).setData(uri) .putExtra(NOTIFICATION_CATEGORY_EXTRA, category) .putExtra(NOTIFICATION_ID_WITHIN_CATEGORY_EXTRA, idWithinCategory); Intent deleteIntent = new Intent(context, DeleteReceiver.class).setData(uri) .putExtra(NOTIFICATION_CATEGORY_EXTRA, category) .putExtra(NOTIFICATION_ID_WITHIN_CATEGORY_EXTRA, idWithinCategory); NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setAutoCancel(true) .setContentIntent(PendingIntent.getBroadcast(context, 0, contentIntent, 0)) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)).setContentTitle(title) .setContentText(text).setGroup(NOTIFICATION_TAG).setDefaults(NotificationCompat.DEFAULT_LIGHTS) .setPriority(-1).setLargeIcon(image).setSmallIcon(R.drawable.ic_chrome); manager.notify(NOTIFICATION_TAG, nextId, builder.build()); addActiveNotification(new ActiveNotification(nextId, category, idWithinCategory, uri)); // Set timeout. if (timeoutAtMillis != Long.MAX_VALUE) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent timeoutIntent = new Intent(context, TimeoutReceiver.class).setData(Uri.parse(url)) .putExtra(NOTIFICATION_ID_EXTRA, nextId).putExtra(NOTIFICATION_CATEGORY_EXTRA, category) .putExtra(NOTIFICATION_ID_WITHIN_CATEGORY_EXTRA, idWithinCategory); alarmManager.set(AlarmManager.RTC, timeoutAtMillis, PendingIntent.getBroadcast(context, 0, timeoutIntent, PendingIntent.FLAG_UPDATE_CURRENT)); } return true; }
From source file:com.nextgis.firereporter.ReporterService.java
public void ScheduleNextUpdate(Context context, long nMinTimeBetweenSend, boolean bEnergyEconomy) { if (context == null) return;// w w w . java 2s. c o m Intent intent = new Intent(ReporterService.ACTION_START); PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); // The update frequency should often be user configurable. This is not. long currentTimeMillis = System.currentTimeMillis(); long nextUpdateTimeMillis = currentTimeMillis + nMinTimeBetweenSend; Time nextUpdateTime = new Time(); nextUpdateTime.set(nextUpdateTimeMillis); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); if (bEnergyEconomy) alarmManager.set(AlarmManager.RTC, nextUpdateTimeMillis, pendingIntent); else alarmManager.set(AlarmManager.RTC_WAKEUP, nextUpdateTimeMillis, pendingIntent); }
From source file:com.jmstudios.redmoon.receiver.AutomaticFilterChangeReceiver.java
public static void cancelTurnOnAlarm(Context context) { Intent commands = new Intent(context, AutomaticFilterChangeReceiver.class); commands.setData(Uri.parse("turnOnIntent")); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, commands, 0); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(pendingIntent);//from w w w . j a va2 s.co m }
From source file:org.wso2.iot.agent.services.AgentStartupReceiver.java
/** * Initiates device notifier on device startup. * @param context - Application context. *///from w w w .j ava2s . c o m private void setRecurringAlarm(Context context) { Resources resources = context.getApplicationContext().getResources(); String mode = Preference.getString(context, Constants.PreferenceFlag.NOTIFIER_TYPE); boolean isLocked = Preference.getBoolean(context, Constants.IS_LOCKED); String lockMessage = Preference.getString(context, Constants.LOCK_MESSAGE); if (lockMessage == null || lockMessage.isEmpty()) { lockMessage = resources.getString(R.string.txt_lock_activity); } if (isLocked) { Operation lockOperation = new Operation(); lockOperation.setId(DEFAULT_ID); lockOperation.setCode(Constants.Operation.DEVICE_LOCK); try { JSONObject payload = new JSONObject(); payload.put(Constants.ADMIN_MESSAGE, lockMessage); payload.put(Constants.IS_HARD_LOCK_ENABLED, true); lockOperation.setPayLoad(payload.toString()); OperationProcessor operationProcessor = new OperationProcessor(context); operationProcessor.doTask(lockOperation); } catch (AndroidAgentException e) { Log.e(TAG, "Error occurred while executing hard lock operation at the device startup"); } catch (JSONException e) { Log.e(TAG, "Error occurred while building hard lock operation payload"); } } int interval = Preference.getInt(context, context.getResources().getString(R.string.shared_pref_frequency)); if (interval == DEFAULT_INT_VALUE) { interval = Constants.DEFAULT_INTERVAL; } if (mode == null) { mode = Constants.NOTIFIER_LOCAL; } if (Preference.getBoolean(context, Constants.PreferenceFlag.REGISTERED) && Constants.NOTIFIER_LOCAL.equals(mode.trim().toUpperCase(Locale.ENGLISH))) { Intent alarmIntent = new Intent(context, AlarmReceiver.class); PendingIntent recurringAlarmIntent = PendingIntent.getBroadcast(context, Constants.DEFAULT_REQUEST_CODE, alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, Constants.DEFAULT_START_INTERVAL, interval, recurringAlarmIntent); Log.i(TAG, "Setting up alarm manager for polling every " + interval + " milliseconds."); } }
From source file:com.chintans.venturebox.util.Utils.java
public static void setAlarm(Context context, long time, boolean trigger, boolean isRom) { Intent i = new Intent(context, NotificationAlarm.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pi = PendingIntent.getBroadcast(context, isRom ? ROM_ALARM_ID : GAPPS_ALARM_ID, i, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.cancel(pi);//from ww w. j a va2 s .c o m if (time > 0) { am.setInexactRepeating(AlarmManager.RTC_WAKEUP, trigger ? 0 : time, time, pi); } }
From source file:com.ferdi2005.secondgram.NotificationsController.java
public NotificationsController() { notificationManager = NotificationManagerCompat.from(ApplicationLoader.applicationContext); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE); inChatSoundEnabled = preferences.getBoolean("EnableInChatSound", true); try {//from w ww.j av a 2s .c o m audioManager = (AudioManager) ApplicationLoader.applicationContext .getSystemService(Context.AUDIO_SERVICE); } catch (Exception e) { FileLog.e(e); } try { alarmManager = (AlarmManager) ApplicationLoader.applicationContext .getSystemService(Context.ALARM_SERVICE); } catch (Exception e) { FileLog.e(e); } try { PowerManager pm = (PowerManager) ApplicationLoader.applicationContext .getSystemService(Context.POWER_SERVICE); notificationDelayWakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock"); notificationDelayWakelock.setReferenceCounted(false); } catch (Exception e) { FileLog.e(e); } notificationDelayRunnable = new Runnable() { @Override public void run() { FileLog.e("delay reached"); if (!delayedPushMessages.isEmpty()) { showOrUpdateNotification(true); delayedPushMessages.clear(); } try { if (notificationDelayWakelock.isHeld()) { notificationDelayWakelock.release(); } } catch (Exception e) { FileLog.e(e); } } }; }
From source file:com.darshancomputing.BatteryIndicatorPro.BatteryInfoService.java
@Override public void onCreate() { res = getResources();/*from w w w .jav a2 s . c om*/ str = new Str(res); log_db = new LogDatabase(this); info = new BatteryInfo(); messenger = new Messenger(new MessageHandler()); clientMessengers = new java.util.HashSet<Messenger>(); predictor = new Predictor(this); bl = BatteryLevel.getInstance(this, BatteryLevel.SIZE_NOTIFICATION); cwbg = new CircleWidgetBackground(this); alarms = new AlarmDatabase(this); mNotificationManager = NotificationManagerCompat.from(this); mainNotificationB = new NotificationCompat.Builder(this); alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); loadSettingsFiles(); sdkVersioning(); currentHack = CurrentHack.getInstance(this); currentHack.setPreferFS(settings.getBoolean(SettingsActivity.KEY_CURRENT_HACK_PREFER_FS, res.getBoolean(R.bool.default_prefer_fs_current_hack))); Intent currentInfoIntent = new Intent(this, BatteryInfoActivity.class).putExtra(EXTRA_CURRENT_INFO, true); currentInfoPendingIntent = PendingIntent.getActivity(this, RC_MAIN, currentInfoIntent, 0); Intent updatePredictorIntent = new Intent(this, BatteryInfoService.class); updatePredictorIntent.putExtra(EXTRA_UPDATE_PREDICTOR, true); updatePredictorPendingIntent = PendingIntent.getService(this, 0, updatePredictorIntent, 0); Intent alarmsIntent = new Intent(this, BatteryInfoActivity.class).putExtra(EXTRA_EDIT_ALARMS, true); alarmsPendingIntent = PendingIntent.getActivity(this, RC_ALARMS, alarmsIntent, 0); widgetManager = AppWidgetManager.getInstance(this); Class[] appWidgetProviders = { BatteryInfoAppWidgetProvider.class, /* Circle widget! */ FullAppWidgetProvider.class }; for (int i = 0; i < appWidgetProviders.length; i++) { int[] ids = widgetManager.getAppWidgetIds(new ComponentName(this, appWidgetProviders[i])); for (int j = 0; j < ids.length; j++) { widgetIds.add(ids[j]); } } Intent bc_intent = registerReceiver(mBatteryInfoReceiver, batteryChanged); info.load(bc_intent, sp_service); }
From source file:com.mobilyzer.MeasurementScheduler.java
@Override public void onCreate() { Logger.d("MeasurementScheduler -> onCreate called"); PhoneUtils.setGlobalContext(this.getApplicationContext()); phoneUtils = PhoneUtils.getPhoneUtils(); phoneUtils.registerSignalStrengthListener(); this.measurementExecutor = Executors.newSingleThreadExecutor(); this.mainQueue = new PriorityBlockingQueue<MeasurementTask>(Config.MAX_TASK_QUEUE_SIZE, new TaskComparator()); this.waitingTasksQueue = new PriorityBlockingQueue<MeasurementTask>(Config.MAX_TASK_QUEUE_SIZE, new WaitingTasksComparator()); this.pendingTasks = new ConcurrentHashMap<MeasurementTask, Future<MeasurementResult[]>>(); this.tasksStatus = new ConcurrentHashMap<String, MeasurementScheduler.TaskStatus>(); this.alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); this.resourceCapManager = new ResourceCapManager(Config.DEFAULT_BATTERY_THRESH_PRECENT, this); this.serverTasks = new HashMap<String, Date>(); // this.currentSchedule = new HashMap<String, MeasurementTask>(); this.idToClientKey = new ConcurrentHashMap<String, String>(); messenger = new Messenger(new APIRequestHandler(this)); gcmManager = new GCMManager(this.getApplicationContext()); this.setCurrentTask(null); this.setCurrentTaskStartTime(null); this.checkin = new Checkin(this); this.checkinRetryIntervalSec = Config.MIN_CHECKIN_RETRY_INTERVAL_SEC; this.checkinRetryCnt = 0; this.checkinTask = new CheckinTask(); this.batteryThreshold = -1; this.checkinIntervalSec = -1; this.dataUsageProfile = DataUsageProfile.NOTASSIGNED; // loadSchedulerState();//TODO(ASHKAN) // Register activity specific BroadcastReceiver here IntentFilter filter = new IntentFilter(); filter.addAction(UpdateIntent.CHECKIN_ACTION); filter.addAction(UpdateIntent.CHECKIN_RETRY_ACTION); filter.addAction(UpdateIntent.MEASUREMENT_ACTION); filter.addAction(UpdateIntent.MEASUREMENT_PROGRESS_UPDATE_ACTION); filter.addAction(UpdateIntent.GCM_MEASUREMENT_ACTION); filter.addAction(UpdateIntent.PLT_MEASUREMENT_ACTION); broadcastReceiver = new BroadcastReceiver() { @Override/*from ww w . j av a 2s . com*/ public void onReceive(Context context, Intent intent) { Logger.d(intent.getAction() + " RECEIVED"); if (intent.getAction().equals(UpdateIntent.MEASUREMENT_ACTION)) { handleMeasurement(); } else if (intent.getAction().equals(UpdateIntent.GCM_MEASUREMENT_ACTION)) { try { JSONObject json = new JSONObject( intent.getExtras().getString(UpdateIntent.MEASUREMENT_TASK_PAYLOAD)); Logger.d("MeasurementScheduler -> GCMManager: json task Value is " + json); if (json != null && MeasurementTask.getMeasurementTypes().contains(json.get("type"))) { try { MeasurementTask task = MeasurementJsonConvertor.makeMeasurementTaskFromJson(json); task.getDescription().priority = MeasurementTask.GCM_PRIORITY; task.getDescription().startTime = new Date(System.currentTimeMillis() - 1000); task.getDescription().endTime = new Date(System.currentTimeMillis() + (600 * 1000)); task.generateTaskID(); task.getDescription().key = Config.SERVER_TASK_CLIENT_KEY; submitTask(task); } catch (IllegalArgumentException e) { Logger.w("MeasurementScheduler -> GCM : Could not create task from JSON: " + e); } } } catch (JSONException e) { Logger.e( "MeasurementSchedule -> GCMManager : Got exception during converting GCM json to MeasurementTask", e); } } else if (intent.getAction().equals(UpdateIntent.MEASUREMENT_PROGRESS_UPDATE_ACTION)) { String taskid = intent.getStringExtra(UpdateIntent.TASKID_PAYLOAD); String taskKey = intent.getStringExtra(UpdateIntent.CLIENTKEY_PAYLOAD); int priority = intent.getIntExtra(UpdateIntent.TASK_PRIORITY_PAYLOAD, MeasurementTask.INVALID_PRIORITY); Logger.e( intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD) + " " + taskid + " " + taskKey); if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD).equals(Config.TASK_FINISHED)) { tasksStatus.put(taskid, TaskStatus.FINISHED); Parcelable[] results = intent.getParcelableArrayExtra(UpdateIntent.RESULT_PAYLOAD); if (results != null) { sendResultToClient(results, priority, taskKey, taskid); for (Object obj : results) { try { MeasurementResult result = (MeasurementResult) obj; /** * Nullify the additional parameters in MeasurmentDesc, or the results won't be * accepted by GAE server */ result.getMeasurementDesc().parameters = null; String jsonResult = MeasurementJsonConvertor.encodeToJson(result).toString(); saveResultToFile(jsonResult); } catch (JSONException e) { Logger.e("Error converting results to json format", e); } } } handleMeasurement(); } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD).equals(Config.TASK_PAUSED)) { tasksStatus.put(taskid, TaskStatus.PAUSED); } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD) .equals(Config.TASK_STOPPED)) { tasksStatus.put(taskid, TaskStatus.SCHEDULED); } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD) .equals(Config.TASK_CANCELED)) { tasksStatus.put(taskid, TaskStatus.CANCELLED); Parcelable[] results = intent.getParcelableArrayExtra(UpdateIntent.RESULT_PAYLOAD); if (results != null) { sendResultToClient(results, priority, taskKey, taskid); } } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD) .equals(Config.TASK_STARTED)) { tasksStatus.put(taskid, TaskStatus.RUNNING); } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD) .equals(Config.TASK_RESUMED)) { tasksStatus.put(taskid, TaskStatus.RUNNING); } } else if (intent.getAction().equals(UpdateIntent.CHECKIN_ACTION) || intent.getAction().equals(UpdateIntent.CHECKIN_RETRY_ACTION)) { Logger.d("Checkin intent received"); handleCheckin(); } } }; this.registerReceiver(broadcastReceiver, filter); }