当前位置: 首页>>代码示例>>Java>>正文


Java GcmNetworkManager.schedule方法代码示例

本文整理汇总了Java中com.google.android.gms.gcm.GcmNetworkManager.schedule方法的典型用法代码示例。如果您正苦于以下问题:Java GcmNetworkManager.schedule方法的具体用法?Java GcmNetworkManager.schedule怎么用?Java GcmNetworkManager.schedule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.android.gms.gcm.GcmNetworkManager的用法示例。


在下文中一共展示了GcmNetworkManager.schedule方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: schedule

import com.google.android.gms.gcm.GcmNetworkManager; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:28,代码来源:BackgroundScheduler.java

示例2: schedule

import com.google.android.gms.gcm.GcmNetworkManager; //导入方法依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:23,代码来源:DownloadResumptionScheduler.java

示例3: scheduleLaunchTask

import com.google.android.gms.gcm.GcmNetworkManager; //导入方法依赖的package包/类
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;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:25,代码来源:BackgroundSyncLauncher.java

示例4: onClick

import com.google.android.gms.gcm.GcmNetworkManager; //导入方法依赖的package包/类
@Override
public void onClick(View v) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(AccountSettingsActivity.this);
    sharedPreferences.edit().putString("firstName", firstName.getText().toString()).apply();
    sharedPreferences.edit().putString("lastName", lastName.getText().toString()).apply();
    sharedPreferences.edit().putString("age",age.getText().toString()).apply();

    GcmNetworkManager gcmNM = GcmNetworkManager.getInstance(AccountSettingsActivity.this);
    Log.i(TAG, "Registering the BackupTask");
    OneoffTask task = new OneoffTask.Builder()
            .setService(MyBackupService.class)
            .setTag(TASK_BACKUP)
            .setExecutionWindow(0L, ONE_HOUR)
            .setRequiredNetwork(Task.NETWORK_STATE_UNMETERED)
            .setRequiresCharging(true)
            .setUpdateCurrent(true)
            .build();

    gcmNM.schedule(task);
}
 
开发者ID:PacktPublishing,项目名称:Asynchronous-Android-Programming,代码行数:21,代码来源:AccountSettingsActivity.java

示例5: schedule

import com.google.android.gms.gcm.GcmNetworkManager; //导入方法依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:23,代码来源:DownloadResumptionScheduler.java

示例6: scheduleLaunchTask

import com.google.android.gms.gcm.GcmNetworkManager; //导入方法依赖的package包/类
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;
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:24,代码来源:BackgroundSyncLauncher.java

示例7: schedule

import com.google.android.gms.gcm.GcmNetworkManager; //导入方法依赖的package包/类
@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;
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:23,代码来源:BackgroundTaskSchedulerGcmNetworkManager.java

示例8: onStop

import com.google.android.gms.gcm.GcmNetworkManager; //导入方法依赖的package包/类
@Override
protected void onStop() {
    super.onStop();
    if (!Once.beenDone(Once.THIS_APP_VERSION, "update")) {
        final GcmNetworkManager manager = GcmNetworkManager.getInstance(this);
        if (mPrefsModel.isBackgroundUpdateServiceEnabled())
            manager.schedule(TimelineUpdateService.create(mPrefsModel.backgroundUpdateInterval() / 1000));
        manager.schedule(AccountUpdateService.create());
        Once.markDone("update");
    }
}
 
开发者ID:mecid,项目名称:robird-reborn,代码行数:12,代码来源:HomeActivity.java

示例9: schedule

import com.google.android.gms.gcm.GcmNetworkManager; //导入方法依赖的package包/类
public void schedule(@NonNull GcmNetworkManager networkManager) throws IllegalStateException{
    if (tag == null) {
        throw new IllegalStateException("Tag cannot be null for WindowTask, it is used for rescheduling to the right time");
    }
    else if (windowHours == 0) {
        throw new IllegalStateException("Window hours not defined");
    }

    if (extras == null){
        extras = new Bundle();
    }
    extras.putBoolean(KEY_REQUIRES_CHARGING, requiresCharging);
    extras.putInt(KEY_REQUIRED_NETWORK, requiredNetworkState);
    extras.putInt(KEY_WINDOW_HOURS, windowHours);
    extras.putInt(KEY_START_MINUTE, startMinute);
    extras.putInt(KEY_START_HOUR, startHour);
    extras.putBoolean(KEY_PERSISTED, persisted);
    extras.putBoolean(KEY_UPDATE_CURRENT, updateCurrent);
    extras.putBoolean(KEY_STRICT, strict);

    networkManager.cancelTask(tag, service);
    PeriodicTask.Builder task = new PeriodicTask.Builder()
            .setService(service)
            .setPersisted(persisted)
            .setRequiresCharging(requiresCharging)
            .setRequiredNetwork(requiredNetworkState)
            .setTag(tag)
            .setUpdateCurrent(updateCurrent)
            .setExtras(extras)
            .setPeriod(getPeriod())
            .setFlex(windowHours * 60);
    networkManager.schedule(task.build());
}
 
开发者ID:raveeshbhalla,项目名称:WindowJobScheduler,代码行数:34,代码来源:WindowTask.java

示例10: scheduleImpl

import com.google.android.gms.gcm.GcmNetworkManager; //导入方法依赖的package包/类
@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);
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:28,代码来源:BackgroundGcmScheduler.java

示例11: scheduleSmartlistSync

import com.google.android.gms.gcm.GcmNetworkManager; //导入方法依赖的package包/类
public void scheduleSmartlistSync() {

        GcmNetworkManager gcm = GcmNetworkManager.getInstance(m_context);

        OneoffTask syncTask = new OneoffTask.Builder()
                .setService(ManualSyncService.class)
                .setExecutionWindow(5, 30)
                .setTag("sync-smartlist")
                .setUpdateCurrent(true)
                .setRequiredNetwork(Task.NETWORK_STATE_ANY)
                .build();

        gcm.schedule(syncTask);
    }
 
开发者ID:johncarpenter,项目名称:MarketAndroid,代码行数:15,代码来源:AccountUtils.java

示例12: onCreate

import com.google.android.gms.gcm.GcmNetworkManager; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
    super.onCreate(savedInstanceState, persistentState);
    GcmNetworkManager mGcmNetworkManager = GcmNetworkManager.getInstance(this);
    mGcmNetworkManager.schedule(createOnoffTask());
}
 
开发者ID:PacktPublishing,项目名称:Android-High-Performance-Programming,代码行数:7,代码来源:GcmNetworkManagerActivity.java


注:本文中的com.google.android.gms.gcm.GcmNetworkManager.schedule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。