本文整理汇总了Java中com.google.android.gms.gcm.Task类的典型用法代码示例。如果您正苦于以下问题:Java Task类的具体用法?Java Task怎么用?Java Task使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Task类属于com.google.android.gms.gcm包,在下文中一共展示了Task类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scheduleDispatchLocationService
import com.google.android.gms.gcm.Task; //导入依赖的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);
}
示例2: schedule
import com.google.android.gms.gcm.Task; //导入依赖的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);
}
示例3: schedule
import com.google.android.gms.gcm.Task; //导入依赖的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
示例4: scheduleLaunchTask
import com.google.android.gms.gcm.Task; //导入依赖的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.Task; //导入依赖的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.Task; //导入依赖的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: sendRegistrationToServer
import com.google.android.gms.gcm.Task; //导入依赖的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());
}
}
示例8: scheduleSensorLogsUploadTask
import com.google.android.gms.gcm.Task; //导入依赖的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
示例9: scheduleOneTimeTask
import com.google.android.gms.gcm.Task; //导入依赖的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
示例10: scheduleAction
import com.google.android.gms.gcm.Task; //导入依赖的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.Task; //导入依赖的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.Task; //导入依赖的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: createTaskFromTaskInfo
import com.google.android.gms.gcm.Task; //导入依赖的package包/类
@VisibleForTesting
static Task createTaskFromTaskInfo(@NonNull TaskInfo taskInfo) {
Bundle taskExtras = new Bundle();
taskExtras.putString(
BACKGROUND_TASK_CLASS_KEY, taskInfo.getBackgroundTaskClass().getName());
taskExtras.putBundle(BACKGROUND_TASK_EXTRAS_KEY, taskInfo.getExtras());
Task.Builder builder;
if (taskInfo.isPeriodic()) {
builder = getPeriodicTaskBuilder(taskInfo.getPeriodicInfo());
} else {
builder = getOneOffTaskBuilder(taskInfo.getOneOffInfo());
}
builder.setExtras(taskExtras)
.setPersisted(taskInfo.isPersisted())
.setRequiredNetwork(getGcmNetworkManagerNetworkTypeFromTypeFromTaskNetworkType(
taskInfo.getRequiredNetworkType()))
.setRequiresCharging(taskInfo.requiresCharging())
.setService(BackgroundTaskGcmTaskService.class)
.setTag(taskIdToTaskTag(taskInfo.getTaskId()))
.setUpdateCurrent(taskInfo.shouldUpdateCurrent());
return builder.build();
}
示例14: schedule
import com.google.android.gms.gcm.Task; //导入依赖的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;
}
示例15: scheduleOneOff
import com.google.android.gms.gcm.Task; //导入依赖的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);
}