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


Java GcmNetworkManager.getInstance方法代码示例

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


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

示例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: 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(scheduler, 0);
                    }
                }
            };
    BackgroundSyncLauncher.shouldLaunchBrowserIfStopped(callback);
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:27,代码来源:BackgroundSyncLauncher.java

示例7: onCreate

import com.google.android.gms.gcm.GcmNetworkManager; //导入方法依赖的package包/类
void onCreate() {
    SQLiteOpenHelper helper = new DatabaseHelper(context);
    locations = new LocationDatabase(helper);
    networkManager = GcmNetworkManager.getInstance(context);
    alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    registerForLocalBroadcastEvents();
    setServiceStatusOnStart();
    Log.d(TAG, "Inside onCreate of Location service Helper");
}
 
开发者ID:OpenLocate,项目名称:openlocate-android,代码行数:10,代码来源:LocationServiceHelper.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: onCreate

import com.google.android.gms.gcm.GcmNetworkManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // [START get_gcm_network_manager]
    mGcmNetworkManager = GcmNetworkManager.getInstance(this);
    // [END get_gcm_network_manager]

    // BroadcastReceiver to get information from MyTaskService about task completion.
    mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(MyTaskService.ACTION_DONE)) {
                String tag = intent.getStringExtra(MyTaskService.EXTRA_TAG);
                int result = intent.getIntExtra(MyTaskService.EXTRA_RESULT, -1);

                String msg = String.format("DONE: %s (%d)", tag, result);
                Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
            }
        }
    };

    findViewById(R.id.button_start_wifi_task).setOnClickListener(this);
    findViewById(R.id.button_start_charging_task).setOnClickListener(this);
    findViewById(R.id.button_turn_on_wifi).setOnClickListener(this);
    findViewById(R.id.button_start_periodic_task).setOnClickListener(this);
    findViewById(R.id.button_stop_periodic_task).setOnClickListener(this);

    // Check that Google Play Services is available, since we need it to use GcmNetworkManager
    // but the API does not use GoogleApiClient, which would normally perform the check
    // automatically.
    checkPlayServicesAvailable();
}
 
开发者ID:googlesamples,项目名称:android-gcmnetworkmanager,代码行数:35,代码来源:MainActivity.java

示例10: onCreateView

import com.google.android.gms.gcm.GcmNetworkManager; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    View view = inflater.inflate(R.layout.fragment_network_scheduler, container, false);
    view.findViewById(R.id.scheduler_add_oneoff).setOnClickListener(this);
    view.findViewById(R.id.scheduler_add_periodic).setOnClickListener(this);
    setHtmlMode(view, R.id.scheduler_description);

    mScheduler = GcmNetworkManager.getInstance(getActivity());
    mTasks = TaskCollection.getInstance(getActivity());

    return view;
}
 
开发者ID:google,项目名称:gcm,代码行数:13,代码来源:NetworkSchedulerFragment.java

示例11: ActionsSchedulerGcmImpl

import com.google.android.gms.gcm.GcmNetworkManager; //导入方法依赖的package包/类
public ActionsSchedulerGcmImpl(Context context, Gson gson,
                               AndroidBasicActionMapper androidBasicActionMapper,
                               GoogleApiPermissionChecker googleApiPermissionChecker,
                               OrchextraLogger orchextraLogger) {

  googleApiPermissionChecker.checkPlayServicesStatus();

  this.gcmNetworkManager = GcmNetworkManager.getInstance(context);
  this.androidBasicActionMapper = androidBasicActionMapper;
  this.gson = gson;
  this.orchextraLogger = orchextraLogger;
}
 
开发者ID:Orchextra,项目名称:orchextra-android-sdk,代码行数:13,代码来源:ActionsSchedulerGcmImpl.java

示例12: getGcmNetworkManager

import com.google.android.gms.gcm.GcmNetworkManager; //导入方法依赖的package包/类
private GcmNetworkManager getGcmNetworkManager() {
    if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(getContext())
            == ConnectionResult.SUCCESS) {
        return GcmNetworkManager.getInstance(getContext());
    }
    return null;
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:8,代码来源:BackgroundGcmScheduler.java

示例13: getGcmNetworkManager

import com.google.android.gms.gcm.GcmNetworkManager; //导入方法依赖的package包/类
private GcmNetworkManager getGcmNetworkManager(Context context) {
    if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context)
            == ConnectionResult.SUCCESS) {
        return GcmNetworkManager.getInstance(context);
    }
    return null;
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:8,代码来源:BackgroundTaskSchedulerGcmNetworkManager.java

示例14: get

import com.google.android.gms.gcm.GcmNetworkManager; //导入方法依赖的package包/类
/**
 * A getter method for AndroidGcmController singleton which also initializes it if it wasn't
 * already initialized.
 *
 * @param context the application context.
 * @return a singleton instance of the AndroidGcmController
 */
public static AndroidGcmController get(Context context) {
  synchronized (lock) {
    if (androidGcmController == null) {
      androidGcmController =
          new AndroidGcmController(context, GcmNetworkManager.getInstance(context));
    }
  }
  return androidGcmController;
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:17,代码来源:AndroidGcmController.java

示例15: 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


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