com.google.android.gms.gcm.PeriodicTask Java Examples
The following examples show how to use
com.google.android.gms.gcm.PeriodicTask.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RegistrationIntentService.java From xDrip with GNU General Public License v3.0 | 6 votes |
private void sendRegistrationToServer(String token) { try { Log.d(TAG, "Scheduling tasks"); PeriodicTask task = new PeriodicTask.Builder() .setService(TaskService.class) .setTag(GcmActivity.TASK_TAG_UNMETERED) .setRequiredNetwork(Task.NETWORK_STATE_UNMETERED) .setPeriod(7200L) .build(); GcmNetworkManager.getInstance(this).cancelAllTasks(TaskService.class); GcmNetworkManager.getInstance(this).schedule(task); PlusSyncService.startSyncService(getApplicationContext(), "RegistrationToServer"); GcmActivity.queueCheckOld(getApplicationContext()); } catch (Exception e) { Log.e(TAG, "Exception in sendRegistration: " + e.toString()); } }
Example #2
Source File: RegistrationIntentService.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
private void sendRegistrationToServer(String token) { try { Log.d(TAG, "Scheduling tasks"); PeriodicTask task = new PeriodicTask.Builder() .setService(TaskService.class) .setTag(GcmActivity.TASK_TAG_UNMETERED) .setRequiredNetwork(Task.NETWORK_STATE_UNMETERED) .setPeriod(7200L) .build(); GcmNetworkManager.getInstance(this).cancelAllTasks(TaskService.class); GcmNetworkManager.getInstance(this).schedule(task); PlusSyncService.startSyncService(getApplicationContext(), "RegistrationToServer"); GcmActivity.queueCheckOld(getApplicationContext()); } catch (Exception e) { Log.e(TAG, "Exception in sendRegistration: " + e.toString()); } }
Example #3
Source File: SnippetsLauncher.java From AndroidChromium with Apache License 2.0 | 6 votes |
private static PeriodicTask buildFetchTask( String tag, long periodSeconds, int requiredNetwork) { // Add a bit of "flex" around the target period. This achieves the following: // - It makes sure the task doesn't run (significantly) before its initial period has // elapsed. In practice, the scheduler seems to behave like that anyway, but it doesn't // guarantee that, so we shouldn't rely on it. // - It gives the scheduler a bit of room to optimize for battery life. long effectivePeriodSeconds = (long) (periodSeconds * (1.0 + FLEX_FACTOR)); long flexSeconds = (long) (periodSeconds * (2.0 * FLEX_FACTOR)); return new PeriodicTask.Builder() .setService(ChromeBackgroundService.class) .setTag(tag) .setPeriod(effectivePeriodSeconds) .setFlex(flexSeconds) .setRequiredNetwork(requiredNetwork) .setPersisted(true) .setUpdateCurrent(true) .build(); }
Example #4
Source File: NetworkSchedulerFragment.java From gcm with Apache License 2.0 | 6 votes |
private void addPeriodic(long periodSecs, long flexSecs, int connectivity, boolean charging, boolean persistence) { if (flexSecs > periodSecs) { Toast.makeText(getActivity(), getString(R.string.scheduler_error_flex), Toast.LENGTH_SHORT).show(); return; } String tag = Long.toString(SystemClock.currentThreadTimeMillis()); final TaskTracker taskTracker = TaskTracker.createPeriodic(tag, periodSecs, flexSecs); PeriodicTask periodic = new PeriodicTask.Builder() .setService(TaskSchedulerService.class) .setPeriod(periodSecs) .setFlex(flexSecs) .setTag(tag) .setRequiredNetwork(connectivity) .setRequiresCharging(charging) .setPersisted(persistence) .build(); mScheduler.schedule(periodic); mTasks.updateTask(taskTracker); }
Example #5
Source File: SnippetsLauncher.java From 365browser with Apache License 2.0 | 6 votes |
private static PeriodicTask buildFetchTask( String tag, long periodSeconds, int requiredNetwork) { // Add a bit of "flex" around the target period. This achieves the following: // - It makes sure the task doesn't run (significantly) before its initial period has // elapsed. In practice, the scheduler seems to behave like that anyway, but it doesn't // guarantee that, so we shouldn't rely on it. // - It gives the scheduler a bit of room to optimize for battery life. long effectivePeriodSeconds = (long) (periodSeconds * (1.0 + FLEX_FACTOR)); long flexSeconds = (long) (periodSeconds * (2.0 * FLEX_FACTOR)); return new PeriodicTask.Builder() .setService(ChromeBackgroundService.class) .setTag(tag) .setPeriod(effectivePeriodSeconds) .setFlex(flexSeconds) .setRequiredNetwork(requiredNetwork) .setPersisted(true) .setUpdateCurrent(true) .build(); }
Example #6
Source File: PrecacheController.java From delion with Apache License 2.0 | 5 votes |
/** * Schedules a periodic task to precache resources. * @param context The application context. * @return false if the task cannot be scheduled. */ private static boolean schedulePeriodicPrecacheTask(Context context) { PeriodicTask task = new PeriodicTask.Builder() .setPeriod(WAIT_UNTIL_NEXT_PRECACHE_SECONDS) .setPersisted(true) .setRequiredNetwork(PeriodicTask.NETWORK_STATE_UNMETERED) .setRequiresCharging(true) .setService(ChromeBackgroundService.class) .setTag(PERIODIC_TASK_TAG) .build(); return sTaskScheduler.scheduleTask(context, task); }
Example #7
Source File: SnippetsLauncher.java From delion with Apache License 2.0 | 5 votes |
private static PeriodicTask buildFetchTask( String tag, long periodSeconds, int requiredNetwork, boolean requiresCharging) { return new PeriodicTask.Builder() .setService(ChromeBackgroundService.class) .setTag(tag) .setPeriod(periodSeconds) .setRequiredNetwork(requiredNetwork) .setRequiresCharging(requiresCharging) .setPersisted(true) .setUpdateCurrent(true) .build(); }
Example #8
Source File: PrecacheController.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Schedules a periodic task to precache resources. * @param context The application context. * @return false if the task cannot be scheduled. */ private static boolean schedulePeriodicPrecacheTask(Context context) { PeriodicTask task = new PeriodicTask.Builder() .setPeriod(WAIT_UNTIL_NEXT_PRECACHE_SECONDS) .setPersisted(true) .setRequiredNetwork(PeriodicTask.NETWORK_STATE_UNMETERED) .setRequiresCharging(ChromeVersionInfo.isStableBuild()) .setService(ChromeBackgroundService.class) .setTag(PERIODIC_TASK_TAG) .build(); return sTaskScheduler.scheduleTask(context, task); }
Example #9
Source File: MainActivity.java From android-gcmnetworkmanager with Apache License 2.0 | 5 votes |
public void startPeriodicTask() { Log.d(TAG, "startPeriodicTask"); // [START start_periodic_task] PeriodicTask task = new PeriodicTask.Builder() .setService(MyTaskService.class) .setTag(TASK_TAG_PERIODIC) .setPeriod(30L) .build(); mGcmNetworkManager.schedule(task); // [END start_periodic_task] }
Example #10
Source File: PrecacheController.java From 365browser with Apache License 2.0 | 5 votes |
/** * Schedules a periodic task to precache resources. * @param context The application context. * @return false if the task cannot be scheduled. */ private static boolean schedulePeriodicPrecacheTask(Context context) { PeriodicTask task = new PeriodicTask.Builder() .setPeriod(WAIT_UNTIL_NEXT_PRECACHE_SECONDS) .setPersisted(true) .setRequiredNetwork(PeriodicTask.NETWORK_STATE_UNMETERED) .setRequiresCharging(ChromeVersionInfo.isStableBuild()) .setService(ChromeBackgroundService.class) .setTag(PERIODIC_TASK_TAG) .build(); return sTaskScheduler.scheduleTask(context, task); }
Example #11
Source File: BackgroundTaskSchedulerGcmNetworkManager.java From 365browser with Apache License 2.0 | 5 votes |
private static Task.Builder getPeriodicTaskBuilder(TaskInfo.PeriodicInfo periodicInfo) { PeriodicTask.Builder builder = new PeriodicTask.Builder(); builder.setPeriod(TimeUnit.MILLISECONDS.toSeconds(periodicInfo.getIntervalMs())); if (periodicInfo.hasFlex()) { builder.setFlex(TimeUnit.MILLISECONDS.toSeconds(periodicInfo.getFlexMs())); } return builder; }