本文整理汇总了Java中com.google.android.gms.gcm.OneoffTask类的典型用法代码示例。如果您正苦于以下问题:Java OneoffTask类的具体用法?Java OneoffTask怎么用?Java OneoffTask使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OneoffTask类属于com.google.android.gms.gcm包,在下文中一共展示了OneoffTask类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: schedule
import com.google.android.gms.gcm.OneoffTask; //导入依赖的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);
}
示例2: schedule
import com.google.android.gms.gcm.OneoffTask; //导入依赖的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: schedulePrecacheCompletionTask
import com.google.android.gms.gcm.OneoffTask; //导入依赖的package包/类
/**
* Schedules a one-off task to finish precaching the resources that were
* still outstanding when the last task was interrupted. Interrupting such
* a one-off task will result in scheduling a new one.
* @param context The application context.
*/
private static void schedulePrecacheCompletionTask(Context context) {
Log.v(TAG, "scheduling a precache completion task");
OneoffTask task = new OneoffTask.Builder()
.setExecutionWindow(COMPLETION_TASK_MIN_DELAY_SECONDS,
COMPLETION_TASK_MAX_DELAY_SECONDS)
.setPersisted(true)
.setRequiredNetwork(OneoffTask.NETWORK_STATE_UNMETERED)
.setRequiresCharging(ChromeVersionInfo.isStableBuild())
.setService(ChromeBackgroundService.class)
.setTag(CONTINUATION_TASK_TAG)
.setUpdateCurrent(true)
.build();
if (sTaskScheduler.scheduleTask(context, task)) {
PrecacheUMA.record(PrecacheUMA.Event.ONEOFF_TASK_SCHEDULE);
} else {
PrecacheUMA.record(PrecacheUMA.Event.ONEOFF_TASK_SCHEDULE_FAIL);
}
}
示例4: scheduleLaunchTask
import com.google.android.gms.gcm.OneoffTask; //导入依赖的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;
}
示例5: onClick
import com.google.android.gms.gcm.OneoffTask; //导入依赖的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
示例6: startWifiTask
import com.google.android.gms.gcm.OneoffTask; //导入依赖的package包/类
public void startWifiTask() {
Log.d(TAG, "startWiFiTask");
// Disable WiFi so the task does not start immediately
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(false);
// [START start_one_off_task]
OneoffTask task = new OneoffTask.Builder()
.setService(MyTaskService.class)
.setTag(TASK_TAG_WIFI)
.setExecutionWindow(0L, 3600L)
.setRequiredNetwork(Task.NETWORK_STATE_UNMETERED)
.build();
mGcmNetworkManager.schedule(task);
// [END start_one_off_task]
}
示例7: scheduleSensorLogsUploadTask
import com.google.android.gms.gcm.OneoffTask; //导入依赖的package包/类
/**
* Schedule all sensor LOGS upload one time task
*
* @param context
*/
private void scheduleSensorLogsUploadTask(Context context) {
Log.d(TAG, "Scheduling logs upload one time task...");
OneoffTask oneTimeTask = new Builder()
.setService(LogsUploadService.class)
.setExecutionWindow(UPLOAD_ALL_TASKS_START_SECS,
UPLOAD_ALL_TASKS_END_SECS)
.setTag("onetimetag | 2")
.setPersisted(true)
.setUpdateCurrent(true)
.setRequiredNetwork(Task.NETWORK_STATE_ANY)
.setRequiresCharging(false)
.build();
GcmNetworkManager.getInstance(context).schedule(oneTimeTask);
Log.d(TAG, "Logs upload task was scheduled!");
}
开发者ID:Telecooperation,项目名称:assistance-platform-client-sdk-android,代码行数:25,代码来源:WifiStateReceiver.java
示例8: scheduleOneTimeTask
import com.google.android.gms.gcm.OneoffTask; //导入依赖的package包/类
/**
* Schedules an periodic upload task
*/
public static void scheduleOneTimeTask(Context context, long startSecs, long endSecs, String tag) {
Log.d(TAG, "Scheduling one time task...");
Bundle bundle = new Bundle();
bundle.putInt(UPLOAD_ALL_FLAG_NAME, UPLOAD_ALL_FLAG_VALUE);
OneoffTask oneTimeTask = new Builder()
.setService(SensorUploadService.class)
.setExecutionWindow(startSecs, endSecs)
.setTag(tag)
.setPersisted(true)
.setUpdateCurrent(true)
.setRequiredNetwork(Task.NETWORK_STATE_ANY)
.setRequiresCharging(false)
.setExtras(bundle)
.build();
GcmNetworkManager.getInstance(context).schedule(oneTimeTask);
Log.d(TAG, "One time task was scheduled!");
}
开发者ID:Telecooperation,项目名称:assistance-platform-client-sdk-android,代码行数:26,代码来源:SensorUploadService.java
示例9: addOneOff
import com.google.android.gms.gcm.OneoffTask; //导入依赖的package包/类
private void addOneOff(long winStartSecs, long winEndSecs, int connectivity, boolean charging) {
if (winStartSecs > winEndSecs) {
Toast.makeText(getActivity(),
getString(R.string.scheduler_error_window),
Toast.LENGTH_SHORT).show();
return;
}
String tag = Long.toString(SystemClock.currentThreadTimeMillis());
final long elapsedNowSeconds = SystemClock.elapsedRealtime() / 1000;
final TaskTracker taskTracker = TaskTracker.createOneoff(tag,
elapsedNowSeconds + winStartSecs, elapsedNowSeconds + winEndSecs);
OneoffTask oneOff = new OneoffTask.Builder()
.setService(TaskSchedulerService.class)
.setTag(tag)
.setExecutionWindow(winStartSecs, winEndSecs)
.setRequiredNetwork(connectivity)
// Persistence not yet support for Oneoffs.
.setRequiresCharging(charging)
.build();
mScheduler.schedule(oneOff);
mTasks.updateTask(taskTracker);
}
示例10: scheduleAction
import com.google.android.gms.gcm.OneoffTask; //导入依赖的package包/类
@Override public void scheduleAction(ScheduledAction action) {
AndroidBasicAction androidBasicAction = androidBasicActionMapper.modelToExternalClass(
action.getBasicAction());
Bundle bundle = new Bundle();
bundle.putString(BUNDLE_TASK_PARAM_NAME, gson.toJson(androidBasicAction));
OneoffTask task = new OneoffTask.Builder()
.setService(OrchextraGcmTaskService.class)
.setTag(action.getId())
.setExecutionWindow(action.getScheduleTime()/ONE_SECOND, (action.getScheduleTime()/ONE_SECOND)+DEFAULT_DELAY_MAX)
.setPersisted(true)
.setRequiresCharging(false)
.setRequiredNetwork(Task.NETWORK_STATE_ANY)
.setExtras(bundle)
.build();
logShowTime(action);
orchextraLogger.log("Scheduled action "+ action.getId());
gcmNetworkManager.schedule(task);
}
示例11: schedule
import com.google.android.gms.gcm.OneoffTask; //导入依赖的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);
}
}
示例12: scheduleLaunchTask
import com.google.android.gms.gcm.OneoffTask; //导入依赖的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;
}
示例13: scheduleOneOff
import com.google.android.gms.gcm.OneoffTask; //导入依赖的package包/类
public static void scheduleOneOff(Context context, String what) {
Bundle extras = new Bundle();
extras.putString(EXTRA_KEY, what);
OneoffTask task = new OneoffTask.Builder()
.setService(NetworkGCMTaskService.class)
.setTag(TASK_NETWORK_TAG)
.setExtras(extras)
// Execution window: The time period in which the task will execute.
// First param is the lower bound and the second is the upper bound (both are in seconds).
.setExecutionWindow(0L, 30L)
.setRequiredNetwork(Task.NETWORK_STATE_CONNECTED)
.setUpdateCurrent(true)
.build();
GcmNetworkManager.getInstance(context).schedule(task);
}
示例14: shutdownAndScheduleStartup
import com.google.android.gms.gcm.OneoffTask; //导入依赖的package包/类
private void shutdownAndScheduleStartup(int when) {
Log.i(TAG, "overnight shutdown, seconds to startup: " + when);
com.google.android.gms.gcm.Task task = new OneoffTask.Builder()
.setService(TrackerTaskService.class)
.setExecutionWindow(when, when + 60)
.setUpdateCurrent(true)
.setTag(TrackerTaskService.TAG)
.setRequiredNetwork(com.google.android.gms.gcm.Task.NETWORK_STATE_ANY)
.setRequiresCharging(false)
.build();
GcmNetworkManager.getInstance(this).schedule(task);
stopSelf();
}
示例15: startChargingTask
import com.google.android.gms.gcm.OneoffTask; //导入依赖的package包/类
public void startChargingTask() {
Log.d(TAG, "startChargingTask");
OneoffTask task = new OneoffTask.Builder()
.setService(MyTaskService.class)
.setTag(TASK_TAG_CHARGING)
.setExecutionWindow(0L, 3600L)
.setRequiresCharging(true)
.build();
mGcmNetworkManager.schedule(task);
}