Java Code Examples for com.google.android.gms.gcm.GcmNetworkManager#RESULT_FAILURE

The following examples show how to use com.google.android.gms.gcm.GcmNetworkManager#RESULT_FAILURE . 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: MyTaskService.java    From android-gcmnetworkmanager with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: PlatformGcmService.java    From android-job with Apache License 2.0 6 votes vote down vote up
@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;
    }
}
 
Example 3
Source File: BackgroundTaskGcmTaskService.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public int onRunTask(TaskParams params) {
    final BackgroundTask backgroundTask =
            BackgroundTaskSchedulerGcmNetworkManager.getBackgroundTaskFromTaskParams(params);
    if (backgroundTask == null) {
        Log.w(TAG, "Failed to start task. Could not instantiate class.");
        return GcmNetworkManager.RESULT_FAILURE;
    }

    final TaskParameters taskParams =
            BackgroundTaskSchedulerGcmNetworkManager.getTaskParametersFromTaskParams(params);
    final Waiter waiter = new Waiter(Waiter.MAX_TIMEOUT_SECONDS);

    final AtomicBoolean taskNeedsBackgroundProcessing = new AtomicBoolean();
    ThreadUtils.runOnUiThreadBlocking(new Runnable() {
        @Override
        public void run() {
            taskNeedsBackgroundProcessing.set(
                    backgroundTask.onStartTask(ContextUtils.getApplicationContext(), taskParams,
                            new TaskFinishedCallbackGcmTaskService(waiter)));
        }
    });

    if (!taskNeedsBackgroundProcessing.get()) return GcmNetworkManager.RESULT_SUCCESS;

    waiter.startWaiting();

    if (waiter.isRescheduleNeeded()) return GcmNetworkManager.RESULT_RESCHEDULE;
    if (!waiter.hasTaskTimedOut()) return GcmNetworkManager.RESULT_SUCCESS;

    final AtomicBoolean taskNeedsRescheduling = new AtomicBoolean();
    ThreadUtils.runOnUiThreadBlocking(new Runnable() {
        @Override
        public void run() {
            taskNeedsRescheduling.set(backgroundTask.onStopTask(
                    ContextUtils.getApplicationContext(), taskParams));
        }
    });

    if (taskNeedsRescheduling.get()) return GcmNetworkManager.RESULT_RESCHEDULE;

    return GcmNetworkManager.RESULT_SUCCESS;
}