本文整理汇总了Java中com.google.android.gms.gcm.GcmNetworkManager类的典型用法代码示例。如果您正苦于以下问题:Java GcmNetworkManager类的具体用法?Java GcmNetworkManager怎么用?Java GcmNetworkManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GcmNetworkManager类属于com.google.android.gms.gcm包,在下文中一共展示了GcmNetworkManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: removeScheduledTasks
import com.google.android.gms.gcm.GcmNetworkManager; //导入依赖的package包/类
private static boolean removeScheduledTasks(GcmNetworkManager scheduler) {
// Third-party code causes broadcast to touch disk. http://crbug.com/614679
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
scheduler.cancelTask(TASK_TAG, ChromeBackgroundService.class);
} catch (IllegalArgumentException e) {
// This occurs when BackgroundSyncLauncherService is not found in the application
// manifest. This should not happen in code that reaches here, but has been seen in
// the past. See https://crbug.com/548314
// Disable GCM for the remainder of this session.
setGCMEnabled(false);
// Return false so that the failure will be logged.
return false;
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
return true;
}
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:19,代码来源:BackgroundSyncLauncher.java
示例5: rescheduleTasksOnUpgrade
import com.google.android.gms.gcm.GcmNetworkManager; //导入依赖的package包/类
/**
* Reschedule any required background sync tasks, if they have been removed due to an
* application upgrade.
*
* This method checks the saved preferences, and reschedules the sync tasks as appropriate
* to match the preferences.
* This method is static so that it can be run without actually instantiating a
* BackgroundSyncLauncher.
*/
protected static void rescheduleTasksOnUpgrade(final Context context) {
final GcmNetworkManager scheduler = GcmNetworkManager.getInstance(context);
BackgroundSyncLauncher.ShouldLaunchCallback callback =
new BackgroundSyncLauncher.ShouldLaunchCallback() {
@Override
public void run(Boolean shouldLaunch) {
if (shouldLaunch) {
// It's unclear what time the sync event was supposed to fire, so fire
// without delay and let the browser reschedule if necessary.
// TODO(iclelland): If this fails, report the failure via UMA (not now,
// since the browser is not running, but on next startup.)
scheduleLaunchTask(context, scheduler, 0);
}
}
};
BackgroundSyncLauncher.shouldLaunchBrowserIfStopped(context, callback);
}
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:27,代码来源:BackgroundSyncLauncher.java
示例6: onPreferenceChange
import com.google.android.gms.gcm.GcmNetworkManager; //导入依赖的package包/类
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
// UI or Streaming preference changed
if (preference == mThemePreference || preference == mHighlightTimelineLinksPreference ||
preference == mShowClientNameInTimelinePreference || preference == mTimelineFontSizePreference ||
preference == mHideMediaPreference || preference == mHideAvatarsPreference ||
preference == mShowAbsoluteTimePreference || preference == mCompactTimelinePreference ||
preference == mShowMediaPreviewPreference ||
preference == mStreamingPreference || mStreamingOnWifiPreference == preference) {
Snackbar.make(getActivity().findViewById(R.id.coordinator),
R.string.need_app_restart, Snackbar.LENGTH_INDEFINITE).show();
}
if (preference == mTimelineFontSizePreference) {
preference.setSummary((String) o);
} else if (preference == mBackgroundUpdatePreference ||
preference == mBackgroundUpdateIntervalPreference) {
GcmNetworkManager.getInstance(getActivity())
.schedule(TimelineUpdateService.create(mPrefsModel.backgroundUpdateInterval() / 1000));
}
return true;
}
开发者ID:mecid,项目名称:robird-reborn,代码行数:25,代码来源:SettingsFragment.java
示例7: onRunTask
import com.google.android.gms.gcm.GcmNetworkManager; //导入依赖的package包/类
@Override
public int onRunTask(TaskParams taskParams) {
try {
Bundle bundle = taskParams.getExtras();
String taskName = bundle.getString(TaskScheduler.TASK_NAME);
Task task = (Task) Class.forName(taskName).newInstance();
ArrayMap<String, Object> map = new ArrayMap<>(bundle.size());
for (String key : bundle.keySet()) {
map.put(key, bundle.get(key));
}
task.deserialize(map);
if (task.isRunning())
return GcmNetworkManager.RESULT_RESCHEDULE;
task.attach(null, ContextHandle.getApplicationHandle());
task.run();
task.deliverResult(this);
return GcmNetworkManager.RESULT_SUCCESS;
} catch (Exception err) {
LOG.e("Error running task", err);
return GcmNetworkManager.RESULT_FAILURE;
}
}
开发者ID:lifechurch,项目名称:nuclei-android,代码行数:23,代码来源:TaskGcmService.java
示例8: 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
示例9: onRunTask
import com.google.android.gms.gcm.GcmNetworkManager; //导入依赖的package包/类
@Override
public int onRunTask(TaskParams taskParams) {
Log.i(TAG, "Backing up the account settings");
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
Bundle data = new Bundle();
data.putString(FIRST_NAME, sharedPreferences.getString(FIRST_NAME,""));
data.putString(LAST_NAME, sharedPreferences.getString(LAST_NAME,""));
data.putString(AGE, sharedPreferences.getString(AGE,""));
data.putString("resource", RESOURCE);
data.putString("operation", sharedPreferences.getString(OPERATION,""));
String id = Integer.toString(new Random().nextInt());
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(MyBackupService.this);
try {
gcm.send(getString(R.string.gcm_SenderId) + "@gcm.googleapis.com", id, data);
} catch (IOException e) {
Log.e(TAG, "Failed to backup account");
return GcmNetworkManager.RESULT_RESCHEDULE;
}
return GcmNetworkManager.RESULT_SUCCESS;
}
开发者ID:PacktPublishing,项目名称:Asynchronous-Android-Programming,代码行数:25,代码来源:MyBackupService.java
示例10: fetchUrl
import com.google.android.gms.gcm.GcmNetworkManager; //导入依赖的package包/类
private int fetchUrl(OkHttpClient client, String url) {
Request request = new Request.Builder()
.url(url)
.build();
try {
Response response = client.newCall(request).execute();
Log.d(TAG, "fetchUrl:response:" + response.body().string());
if (response.code() != 200) {
return GcmNetworkManager.RESULT_FAILURE;
}
} catch (IOException e) {
Log.e(TAG, "fetchUrl:error" + e.toString());
return GcmNetworkManager.RESULT_FAILURE;
}
return GcmNetworkManager.RESULT_SUCCESS;
}
开发者ID:googlesamples,项目名称:android-gcmnetworkmanager,代码行数:20,代码来源:MyTaskService.java
示例11: onCreate
import com.google.android.gms.gcm.GcmNetworkManager; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Calendar now = Calendar.getInstance();
now.setLenient(true);
new WindowTask()
.setService(SyncService.class)
.setPersisted(true)
.setUpdateCurrent(true)
.setTag(SyncService.TAG)
.setStartTime(now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE) + 2)
.setWindowHours(1)
.schedule(GcmNetworkManager.getInstance(this));
}
开发者ID:raveeshbhalla,项目名称:WindowJobScheduler,代码行数:17,代码来源:MainActivity.java
示例12: onRunTask
import com.google.android.gms.gcm.GcmNetworkManager; //导入依赖的package包/类
@Override
public int onRunTask(TaskParams taskParams) {
Log.d(TAG, "onRunTask: " + taskParams.getTag());
String tag = taskParams.getTag();
// Default result is success.
int result = GcmNetworkManager.RESULT_SUCCESS;
// Choose method based on the tag.
if (GcmActivity.TASK_TAG_UNMETERED.equals(tag)) {
result = doUnmeteredTask();
} else if (GcmActivity.TASK_TAG_CHARGING.equals(tag)) {
result = doChargingTask();
}
// Return one of RESULT_SUCCESS, RESULT_FAILURE, or RESULT_RESCHEDULE
return result;
}
开发者ID:NightscoutFoundation,项目名称:xDrip,代码行数:19,代码来源:TaskService.java
示例13: sendRegistrationToServer
import com.google.android.gms.gcm.GcmNetworkManager; //导入依赖的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
示例14: scheduleSensorLogsUploadTask
import com.google.android.gms.gcm.GcmNetworkManager; //导入依赖的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
示例15: scheduleOneTimeTask
import com.google.android.gms.gcm.GcmNetworkManager; //导入依赖的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
示例16: onRunTask
import com.google.android.gms.gcm.GcmNetworkManager; //导入依赖的package包/类
@Override
public int onRunTask(TaskParams taskParams) {
Log.d(TAG, "Task uploader has started");
// check Airplane Mode enabled
if (ConnectionUtils.isAirplaneModeEnabled(this)) {
Log.d(TAG, "Airplane Mode enabled. Upload request ignored");
return GcmNetworkManager.RESULT_FAILURE;
}
// device is not online
if (!ConnectionUtils.isOnline(this)) {
Log.d(TAG, "Device is not online. Upload request ignored");
return GcmNetworkManager.RESULT_FAILURE;
}
if (daoProvider == null) {
daoProvider = DaoProvider.getInstance(getApplicationContext());
}
Handler handler = new Handler(getMainLooper());
handler.post(this::prepareData);
return GcmNetworkManager.RESULT_SUCCESS;
}
开发者ID:Telecooperation,项目名称:assistance-platform-client-sdk-android,代码行数:27,代码来源:LogsUploadService.java
示例17: onRunTask
import com.google.android.gms.gcm.GcmNetworkManager; //导入依赖的package包/类
@Override
public int onRunTask(TaskParams taskParams) {
Log.d(TAG, "PlanB task has been executed!");
String userToken = PreferenceProvider
.getInstance(getApplicationContext())
.getUserToken();
// only when user is logged in
if (userToken != null && !userToken.isEmpty()) {
HarvesterServiceProvider serviceProvider = HarvesterServiceProvider.getInstance(getApplicationContext());
if (!serviceProvider.isServiceRunning()) {
serviceProvider.startSensingService();
}
if (!serviceProvider.isAccessibilityServiceRunning()) {
serviceProvider.startAccessibilityService();
}
}
return GcmNetworkManager.RESULT_SUCCESS;
}
开发者ID:Telecooperation,项目名称:assistance-platform-client-sdk-android,代码行数:26,代码来源:PlanBService.java
示例18: onRunTask
import com.google.android.gms.gcm.GcmNetworkManager; //导入依赖的package包/类
@Override
public int onRunTask(TaskParams params) {
String tag = params.getTag();
TaskCollection tasks = TaskCollection.getInstance(this);
TaskTracker task = tasks.getTask(tag);
if (task != null) {
task.execute(mLogger);
tasks.updateTask(task);
} else {
mLogger.log(Log.ERROR, "Could not find task with tag " + tag);
task = TaskTracker.emptyTaskWithTag(tag);
task.execute(mLogger);
tasks.updateTask(task);
}
return GcmNetworkManager.RESULT_SUCCESS;
}
开发者ID:google,项目名称:gcm,代码行数:18,代码来源:TaskSchedulerService.java
示例19: onRunTask
import com.google.android.gms.gcm.GcmNetworkManager; //导入依赖的package包/类
@Override
public int onRunTask(TaskParams taskParams) {
if (actionRecovery != null &&
gson != null &&
orchextraLogger != null) {
orchextraLogger.log("Executing Scheduled action " + taskParams.getTag());
try {
Bundle extras = taskParams.getExtras();
String stringAndroidBasicAction = extras.getString(ActionsSchedulerGcmImpl.BUNDLE_TASK_PARAM_NAME);
AndroidBasicAction androidBasicAction = gson.fromJson(stringAndroidBasicAction, AndroidBasicAction.class);
actionRecovery.recoverAction(androidBasicAction);
orchextraLogger.log("Scheduled action Executed and deleted " + taskParams.getTag());
return GcmNetworkManager.RESULT_SUCCESS;
} catch (Exception e) {
orchextraLogger.log("Error retrieving Scheduled action", OrchextraSDKLogLevel.ERROR);
return GcmNetworkManager.RESULT_FAILURE;
}
} else {
return GcmNetworkManager.RESULT_FAILURE;
}
}
开发者ID:Orchextra,项目名称:orchextra-android-sdk,代码行数:23,代码来源:OrchextraGcmTaskService.java
示例20: onRunTask
import com.google.android.gms.gcm.GcmNetworkManager; //导入依赖的package包/类
@Override
public int onRunTask(TaskParams taskParams) {
int jobId = Integer.parseInt(taskParams.getTag());
JobProxy.Common common = new JobProxy.Common(this, CAT, jobId);
JobRequest request = common.getPendingRequest(true, true);
if (request == null) {
return GcmNetworkManager.RESULT_FAILURE;
}
Job.Result result = common.executeJobRequest(request, taskParams.getExtras());
if (Job.Result.SUCCESS.equals(result)) {
return GcmNetworkManager.RESULT_SUCCESS;
} else {
return GcmNetworkManager.RESULT_FAILURE;
}
}
开发者ID:evernote,项目名称:android-job,代码行数:18,代码来源:PlatformGcmService.java
注:本文中的com.google.android.gms.gcm.GcmNetworkManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论