Java Code Examples for com.google.android.gms.gcm.GcmNetworkManager#getInstance()

The following examples show how to use com.google.android.gms.gcm.GcmNetworkManager#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DownloadResumptionScheduler.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 2
Source File: DownloadResumptionScheduler.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 3
Source File: BackgroundSyncLauncher.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 4
Source File: DownloadResumptionScheduler.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 5
Source File: BackgroundGcmScheduler.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private GcmNetworkManager getGcmNetworkManager() {
    if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(getContext())
            == ConnectionResult.SUCCESS) {
        return GcmNetworkManager.getInstance(getContext());
    }
    return null;
}
 
Example 6
Source File: NetworkSchedulerFragment.java    From gcm with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 7
Source File: BackgroundTaskSchedulerGcmNetworkManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private GcmNetworkManager getGcmNetworkManager(Context context) {
    if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context)
            == ConnectionResult.SUCCESS) {
        return GcmNetworkManager.getInstance(context);
    }
    return null;
}
 
Example 8
Source File: AndroidGcmController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 9
Source File: DownloadResumptionScheduler.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Cancels a download resumption task if it is scheduled.
 */
public void cancelTask() {
    GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(mContext);
    gcmNetworkManager.cancelTask(TASK_TAG, ChromeBackgroundService.class);
}
 
Example 10
Source File: DownloadResumptionScheduler.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Cancels a download resumption task if it is scheduled.
 */
public void cancelTask() {
    GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(mContext);
    gcmNetworkManager.cancelTask(TASK_TAG, ChromeBackgroundService.class);
}
 
Example 11
Source File: JobProxyGcm.java    From android-job with Apache License 2.0 4 votes vote down vote up
public JobProxyGcm(Context context) {
    mContext = context;
    mGcmNetworkManager = GcmNetworkManager.getInstance(context);
}
 
Example 12
Source File: BackgroundSyncLauncher.java    From 365browser with Apache License 2.0 4 votes vote down vote up
protected BackgroundSyncLauncher() {
    mScheduler = GcmNetworkManager.getInstance(ContextUtils.getApplicationContext());
    launchBrowserIfStopped(false, 0);
}
 
Example 13
Source File: BackgroundSyncLauncher.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
protected BackgroundSyncLauncher(Context context) {
    mScheduler = GcmNetworkManager.getInstance(context);
    launchBrowserIfStopped(context, false, 0);
}
 
Example 14
Source File: SnippetsLauncher.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
protected SnippetsLauncher(Context context) {
    checkGCM(context);
    mScheduler = GcmNetworkManager.getInstance(context);
}
 
Example 15
Source File: BackgroundScheduler.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Cancel any outstanding GCM Network Manager requests.
 */
public static void unschedule(Context context) {
    // Get the GCM Network Scheduler.
    GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(context);
    gcmNetworkManager.cancelTask(OfflinePageUtils.TASK_TAG, ChromeBackgroundService.class);
}
 
Example 16
Source File: BackgroundScheduler.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Cancel any outstanding GCM Network Manager requests.
 */
public static void unschedule(Context context) {
    // Get the GCM Network Scheduler.
    GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(context);
    gcmNetworkManager.cancelTask(OfflinePageUtils.TASK_TAG, ChromeBackgroundService.class);
}
 
Example 17
Source File: BackgroundSyncLauncher.java    From delion with Apache License 2.0 4 votes vote down vote up
protected BackgroundSyncLauncher(Context context) {
    mScheduler = GcmNetworkManager.getInstance(context);
    launchBrowserIfStopped(context, false, 0);
}
 
Example 18
Source File: SnippetsLauncher.java    From delion with Apache License 2.0 4 votes vote down vote up
protected SnippetsLauncher(Context context) {
    checkGCM(context);
    mScheduler = GcmNetworkManager.getInstance(context);
}
 
Example 19
Source File: DownloadResumptionScheduler.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Cancels a download resumption task if it is scheduled.
 */
public void cancelTask() {
    GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(mContext);
    gcmNetworkManager.cancelTask(TASK_TAG, ChromeBackgroundService.class);
}
 
Example 20
Source File: SnippetsLauncher.java    From 365browser with Apache License 2.0 4 votes vote down vote up
protected SnippetsLauncher() {
    checkGCM();
    mScheduler = GcmNetworkManager.getInstance(ContextUtils.getApplicationContext());
}