Java Code Examples for com.google.android.gms.gcm.GcmNetworkManager#schedule()
The following examples show how to use
com.google.android.gms.gcm.GcmNetworkManager#schedule() .
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: BackgroundScheduler.java From delion with Apache License 2.0 | 6 votes |
/** * For the given Triggering conditions, start a new GCM Network Manager request allowed * to run after {@code delayStartSecs} seconds. */ private static void schedule(Context context, TriggerConditions triggerConditions, long delayStartSecs, boolean overwrite) { // Get the GCM Network Scheduler. GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(context); Bundle taskExtras = new Bundle(); TaskExtrasPacker.packTimeInBundle(taskExtras); TaskExtrasPacker.packTriggerConditionsInBundle(taskExtras, triggerConditions); Task task = new OneoffTask.Builder() .setService(ChromeBackgroundService.class) .setExecutionWindow(delayStartSecs, ONE_WEEK_IN_SECONDS) .setTag(OfflinePageUtils.TASK_TAG) .setUpdateCurrent(overwrite) .setRequiredNetwork(triggerConditions.requireUnmeteredNetwork() ? Task.NETWORK_STATE_UNMETERED : Task.NETWORK_STATE_CONNECTED) .setRequiresCharging(triggerConditions.requirePowerConnected()) .setExtras(taskExtras) .build(); gcmNetworkManager.schedule(task); }
Example 2
Source File: DownloadResumptionScheduler.java From delion with Apache License 2.0 | 6 votes |
/** * Schedules a future task to start download resumption. * @param allowMeteredConnection Whether download resumption can start if connection is metered. */ public void schedule(boolean allowMeteredConnection) { GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(mContext); int networkType = allowMeteredConnection ? Task.NETWORK_STATE_CONNECTED : Task.NETWORK_STATE_UNMETERED; OneoffTask task = new OneoffTask.Builder() .setService(ChromeBackgroundService.class) .setExecutionWindow(0, ONE_DAY_IN_SECONDS) .setTag(TASK_TAG) .setUpdateCurrent(true) .setRequiredNetwork(networkType) .setRequiresCharging(false) .build(); try { gcmNetworkManager.schedule(task); } catch (IllegalArgumentException e) { Log.e(TAG, "unable to schedule resumption task.", e); } }
Example 3
Source File: BackgroundSyncLauncher.java From delion with Apache License 2.0 | 6 votes |
private static boolean scheduleLaunchTask( Context context, GcmNetworkManager scheduler, long minDelayMs) { // Google Play Services may not be up to date, if the application was not installed through // the Play Store. In this case, scheduling the task will fail silently. final long minDelaySecs = minDelayMs / 1000; OneoffTask oneoff = new OneoffTask.Builder() .setService(ChromeBackgroundService.class) .setTag(TASK_TAG) // We have to set a non-zero execution window here .setExecutionWindow(minDelaySecs, minDelaySecs + 1) .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED) .setPersisted(true) .setUpdateCurrent(true) .build(); try { scheduler.schedule(oneoff); } catch (IllegalArgumentException e) { // Disable GCM for the remainder of this session. setGCMEnabled(false); // Return false so that the failure will be logged. return false; } return true; }
Example 4
Source File: BackgroundScheduler.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * For the given Triggering conditions, start a new GCM Network Manager request allowed * to run after {@code delayStartSecs} seconds. */ private static void schedule(Context context, TriggerConditions triggerConditions, long delayStartSecs, boolean overwrite) { // Get the GCM Network Scheduler. GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(context); Bundle taskExtras = new Bundle(); TaskExtrasPacker.packTimeInBundle(taskExtras); TaskExtrasPacker.packTriggerConditionsInBundle(taskExtras, triggerConditions); Task task = new OneoffTask.Builder() .setService(ChromeBackgroundService.class) .setExecutionWindow(delayStartSecs, ONE_WEEK_IN_SECONDS) .setTag(OfflinePageUtils.TASK_TAG) .setUpdateCurrent(overwrite) .setRequiredNetwork(triggerConditions.requireUnmeteredNetwork() ? Task.NETWORK_STATE_UNMETERED : Task.NETWORK_STATE_CONNECTED) .setRequiresCharging(triggerConditions.requirePowerConnected()) .setExtras(taskExtras) .build(); gcmNetworkManager.schedule(task); }
Example 5
Source File: DownloadResumptionScheduler.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * Schedules a future task to start download resumption. * @param allowMeteredConnection Whether download resumption can start if connection is metered. */ public void schedule(boolean allowMeteredConnection) { GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(mContext); int networkType = allowMeteredConnection ? Task.NETWORK_STATE_CONNECTED : Task.NETWORK_STATE_UNMETERED; OneoffTask task = new OneoffTask.Builder() .setService(ChromeBackgroundService.class) .setExecutionWindow(0, ONE_DAY_IN_SECONDS) .setTag(TASK_TAG) .setUpdateCurrent(true) .setRequiredNetwork(networkType) .setRequiresCharging(false) .build(); try { gcmNetworkManager.schedule(task); } catch (IllegalArgumentException e) { Log.e(TAG, "unable to schedule resumption task.", e); } }
Example 6
Source File: BackgroundSyncLauncher.java From AndroidChromium with Apache License 2.0 | 6 votes |
private static boolean scheduleLaunchTask( Context context, GcmNetworkManager scheduler, long minDelayMs) { // Google Play Services may not be up to date, if the application was not installed through // the Play Store. In this case, scheduling the task will fail silently. final long minDelaySecs = minDelayMs / 1000; OneoffTask oneoff = new OneoffTask.Builder() .setService(ChromeBackgroundService.class) .setTag(TASK_TAG) // We have to set a non-zero execution window here .setExecutionWindow(minDelaySecs, minDelaySecs + 1) .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED) .setPersisted(true) .setUpdateCurrent(true) .build(); try { scheduler.schedule(oneoff); } catch (IllegalArgumentException e) { // Disable GCM for the remainder of this session. setGCMEnabled(false); // Return false so that the failure will be logged. return false; } return true; }
Example 7
Source File: DownloadResumptionScheduler.java From 365browser with Apache License 2.0 | 6 votes |
/** * Schedules a future task to start download resumption. * @param allowMeteredConnection Whether download resumption can start if connection is metered. */ public void schedule(boolean allowMeteredConnection) { GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(mContext); int networkType = allowMeteredConnection ? Task.NETWORK_STATE_CONNECTED : Task.NETWORK_STATE_UNMETERED; OneoffTask task = new OneoffTask.Builder() .setService(ChromeBackgroundService.class) .setExecutionWindow(0, ONE_DAY_IN_SECONDS) .setTag(TASK_TAG) .setUpdateCurrent(true) .setRequiredNetwork(networkType) .setRequiresCharging(false) .build(); try { gcmNetworkManager.schedule(task); } catch (IllegalArgumentException e) { Log.e(TAG, "unable to schedule resumption task.", e); } }
Example 8
Source File: BackgroundSyncLauncher.java From 365browser with Apache License 2.0 | 6 votes |
private static boolean scheduleLaunchTask(GcmNetworkManager scheduler, long minDelayMs) { // Google Play Services may not be up to date, if the application was not installed through // the Play Store. In this case, scheduling the task will fail silently. final long minDelaySecs = minDelayMs / 1000; OneoffTask oneoff = new OneoffTask.Builder() .setService(ChromeBackgroundService.class) .setTag(TASK_TAG) // We have to set a non-zero execution window here .setExecutionWindow(minDelaySecs, minDelaySecs + 1) .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED) .setPersisted(true) .setUpdateCurrent(true) .build(); try { scheduler.schedule(oneoff); } catch (IllegalArgumentException e) { // Disable GCM for the remainder of this session. setGCMEnabled(false); // Return false so that the failure will be logged. return false; } return true; }
Example 9
Source File: BackgroundTaskSchedulerGcmNetworkManager.java From 365browser with Apache License 2.0 | 6 votes |
@Override public boolean schedule(Context context, @NonNull TaskInfo taskInfo) { ThreadUtils.assertOnUiThread(); if (!BackgroundTaskScheduler.hasParameterlessPublicConstructor( taskInfo.getBackgroundTaskClass())) { Log.e(TAG, "BackgroundTask " + taskInfo.getBackgroundTaskClass() + " has no parameterless public constructor."); return false; } GcmNetworkManager gcmNetworkManager = getGcmNetworkManager(context); if (gcmNetworkManager == null) { Log.e(TAG, "GcmNetworkManager is not available."); return false; } Task task = createTaskFromTaskInfo(taskInfo); gcmNetworkManager.schedule(task); return true; }
Example 10
Source File: BackgroundGcmScheduler.java From 365browser with Apache License 2.0 | 5 votes |
@Override protected void scheduleImpl(TriggerConditions triggerConditions, long delayStartSeconds, long executionDeadlineSeconds, boolean overwrite) { GcmNetworkManager gcmNetworkManager = getGcmNetworkManager(); if (gcmNetworkManager == null) return; Bundle taskExtras = new Bundle(); TaskExtrasPacker.packTimeInBundle(taskExtras); TaskExtrasPacker.packHoldWakelock(taskExtras); TaskExtrasPacker.packTriggerConditionsInBundle(taskExtras, triggerConditions); Task task = new OneoffTask.Builder() .setService(ChromeBackgroundService.class) .setExecutionWindow(delayStartSeconds, executionDeadlineSeconds) .setTag(OfflinePageUtils.TASK_TAG) .setUpdateCurrent(overwrite) .setRequiredNetwork(triggerConditions.requireUnmeteredNetwork() ? Task.NETWORK_STATE_UNMETERED : Task.NETWORK_STATE_CONNECTED) .setRequiresCharging(triggerConditions.requirePowerConnected()) .setPersisted(true) .setExtras(taskExtras) .build(); // Schedule a task using GCM network manager. gcmNetworkManager.schedule(task); }