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


Java PeriodicTask类代码示例

本文整理汇总了Java中com.google.android.gms.gcm.PeriodicTask的典型用法代码示例。如果您正苦于以下问题:Java PeriodicTask类的具体用法?Java PeriodicTask怎么用?Java PeriodicTask使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PeriodicTask类属于com.google.android.gms.gcm包,在下文中一共展示了PeriodicTask类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: scheduleDispatchLocationService

import com.google.android.gms.gcm.PeriodicTask; //导入依赖的package包/类
private void scheduleDispatchLocationService() {

        if(endpoints == null) {
            return;
        }

        Bundle bundle = new Bundle();
        try {
            bundle.putString(Constants.ENDPOINTS_KEY, OpenLocate.Endpoint.toJson(endpoints));
        } catch (JSONException e) {
            e.printStackTrace();
        }

        PeriodicTask task = new PeriodicTask.Builder()
                .setExtras(bundle)
                .setService(DispatchLocationService.class)
                .setPeriod(transmissionIntervalInSecs)
                .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED)
                .setRequiresCharging(false)
                .setPersisted(true)
                .setUpdateCurrent(true)
                .setTag(LOCATION_DISPATCH_TAG)
                .build();

        networkManager.schedule(task);
    }
 
开发者ID:OpenLocate,项目名称:openlocate-android,代码行数:27,代码来源:LocationServiceHelper.java

示例2: buildFetchTask

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

示例3: sendRegistrationToServer

import com.google.android.gms.gcm.PeriodicTask; //导入依赖的package包/类
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());
    }
}
 
开发者ID:NightscoutFoundation,项目名称:xDrip,代码行数:19,代码来源:RegistrationIntentService.java

示例4: addPeriodic

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

示例5: scheduleAutoUpdate

import com.google.android.gms.gcm.PeriodicTask; //导入依赖的package包/类
public static void scheduleAutoUpdate(Context context) {
    long periodSecs = 60 * 60 * 24;     // Auto-update should be performed no more than once per 24 hours

    PeriodicTask dailyUpdate = new PeriodicTask.Builder()
            .setService(DataUpdateService.class)
            .setPeriod(periodSecs)
            .setTag(AUTO_UPDATE_TASK_NAME)
            .setPersisted(true)
            .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED)
            .setRequiresCharging(false)
            .setUpdateCurrent(true)
            .build();

    GcmNetworkManager.getInstance(context).schedule(dailyUpdate);
    Timber.d("Scheduled auto-update");
}
 
开发者ID:Burning-Man-Earth,项目名称:iBurn-Android,代码行数:17,代码来源:DataUpdateService.java

示例6: schedulePeriodicPrecacheTask

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

示例7: create

import com.google.android.gms.gcm.PeriodicTask; //导入依赖的package包/类
public static PeriodicTask create() {
    return new PeriodicTask.Builder()
            .setService(AccountUpdateService.class)
            .setTag("account_update")
            .setUpdateCurrent(true)
            .setPeriod(24 * 3600)
            .setPersisted(true)
            .build();
}
 
开发者ID:mecid,项目名称:robird-reborn,代码行数:10,代码来源:AccountUpdateService.java

示例8: create

import com.google.android.gms.gcm.PeriodicTask; //导入依赖的package包/类
public static PeriodicTask create(long periodInSeconds) {
    return new PeriodicTask.Builder()
            .setService(TimelineUpdateService.class)
            .setPeriod(periodInSeconds)
            .setTag("timeline_update")
            .setUpdateCurrent(true)
            .setPersisted(true)
            .build();
}
 
开发者ID:mecid,项目名称:robird-reborn,代码行数:10,代码来源:TimelineUpdateService.java

示例9: onClick

import com.google.android.gms.gcm.PeriodicTask; //导入依赖的package包/类
@Override
public void onClick(View v) {
    GcmNetworkManager gcmNM = GcmNetworkManager.getInstance(AccountSettingsActivity.this);
    Log.i(TAG, "Registering Periodic BackupTask");
    PeriodicTask task = new PeriodicTask.Builder()
            .setService(MyBackupService.class)
            .setTag(TASK_PERIODIC_BACKUP)
            .setFlex(TimeUnit.HOURS.toSeconds(1))
            .setRequiredNetwork(Task.NETWORK_STATE_UNMETERED)
            .setRequiresCharging(true)
            .setPeriod(TimeUnit.HOURS.toSeconds(6))
            .setPersisted(true)
            .build();
    gcmNM.schedule(task);
}
 
开发者ID:PacktPublishing,项目名称:Asynchronous-Android-Programming,代码行数:16,代码来源:AccountSettingsActivity.java

示例10: startPeriodicTask

import com.google.android.gms.gcm.PeriodicTask; //导入依赖的package包/类
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]
}
 
开发者ID:googlesamples,项目名称:android-gcmnetworkmanager,代码行数:14,代码来源:MainActivity.java

示例11: createPeriodicTask

import com.google.android.gms.gcm.PeriodicTask; //导入依赖的package包/类
private Task createPeriodicTask() {
    return new PeriodicTask.Builder()
            .setService(MyGcmTaskService.class)
            .setTag(MyGcmTaskService.MY_TASK)
            .setPeriod(5L)
            .build();
}
 
开发者ID:PacktPublishing,项目名称:Android-High-Performance-Programming,代码行数:8,代码来源:GcmNetworkManagerActivity.java

示例12: schedule

import com.google.android.gms.gcm.PeriodicTask; //导入依赖的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

示例13: getPeriodicTaskBuilder

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

示例14: onCreate

import com.google.android.gms.gcm.PeriodicTask; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_stock_list);
    ButterKnife.bind(this);

    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayShowTitleEnabled(true);
    }

    if (findViewById(R.id.stock_detail_container) != null) {
        mTwoPane = true;
    }

    if (savedInstanceState == null) {
        // The intent service is for executing immediate pulls from the Yahoo API
        // GCMTaskService can only schedule tasks, they cannot execute immediately
        Intent stackServiceIntent = new Intent(this, StockIntentService.class);
        // Run the initialize task service so that some stocks appear upon an empty database
        stackServiceIntent.putExtra(StockIntentService.EXTRA_TAG, StockIntentService.ACTION_INIT);
        if (isNetworkAvailable()) {
            startService(stackServiceIntent);
        } else {
            Snackbar.make(mCoordinatorLayout, getString(R.string.no_internet_connection),
                    Snackbar.LENGTH_LONG).show();
        }
    } else {
        mChangeUnits = savedInstanceState.getInt(EXTRA_CHANGE_UNITS);
        if (savedInstanceState.getBoolean(EXTRA_ADD_DIALOG_OPENED, false)) {
            showDialogForAddingStock();
        }
    }

    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mRecyclerView.addOnItemTouchListener(new RecyclerViewItemClickListener(this, this));

    mAdapter = new QuoteCursorAdapter(this, null, mChangeUnits);
    mRecyclerView.setAdapter(mAdapter);

    getLoaderManager().initLoader(CURSOR_LOADER_ID, null, this);

    ItemTouchHelper.Callback callback = new ItemTouchHelperCallback(mAdapter);
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
    itemTouchHelper.attachToRecyclerView(mRecyclerView);

    // Create a periodic task to pull stocks once every hour after the app has been opened.
    // This is so Widget data stays up to date.
    PeriodicTask periodicTask = new PeriodicTask.Builder()
            .setService(StockTaskService.class)
            .setPeriod(/* 1h */ 60 * 60)
            .setFlex(/* 10s */ 10)
            .setTag(StockTaskService.TAG_PERIODIC)
            .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED)
            .setRequiresCharging(false)
            .build();
    // Schedule task with tag "periodic." This ensure that only the stocks present in the DB
    // are updated.
    GcmNetworkManager.getInstance(this).schedule(periodicTask);

}
 
开发者ID:DmitryMalkovich,项目名称:stock-hawk-app,代码行数:61,代码来源:StockListActivity.java

示例15: schedule

import com.google.android.gms.gcm.PeriodicTask; //导入依赖的package包/类
public static void schedule(Context context, PeriodicTask task, GregorianCalendar start, int windowHours){
    Intent intent = new Intent(context, ScheduleReceiver.class);

}
 
开发者ID:raveeshbhalla,项目名称:WindowJobScheduler,代码行数:5,代码来源:WindowJobScheduler.java


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