Java Code Examples for com.google.android.gms.common.api.Status#isSuccess()

The following examples show how to use com.google.android.gms.common.api.Status#isSuccess() . 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: GoogleDriveClient.java    From financisto with GNU General Public License v2.0 6 votes vote down vote up
@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void doBackup(DoDriveBackup event) {
    DatabaseExport export = new DatabaseExport(context, db.db(), true);
    try {
        String targetFolder = getDriveFolderName();
        ConnectionResult connectionResult = connect();
        if (connectionResult.isSuccess()) {
            DriveFolder folder = getDriveFolder(targetFolder);
            String fileName = export.generateFilename();
            byte[] bytes = export.generateBackupBytes();
            Status status = createFile(folder, fileName, bytes);
            if (status.isSuccess()) {
                handleSuccess(fileName);
            } else {
                handleFailure(status);
            }
        } else {
            handleConnectionResult(connectionResult);
        }
    } catch (Exception e) {
        handleError(e);
    }
}
 
Example 2
Source File: GoogleDriveClient.java    From financisto with GNU General Public License v2.0 6 votes vote down vote up
private Status createFile(DriveFolder folder, String fileName, byte[] bytes) throws IOException {
    MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
            .setTitle(fileName)
            .setMimeType(Export.BACKUP_MIME_TYPE).build();
    // Create a file in the root folder
    DriveApi.DriveContentsResult contentsResult = Drive.DriveApi.newDriveContents(googleApiClient).await();
    Status contentsResultStatus = contentsResult.getStatus();
    if (contentsResultStatus.isSuccess()) {
        DriveContents contents = contentsResult.getDriveContents();
        contents.getOutputStream().write(bytes);
        DriveFolder.DriveFileResult fileResult = folder.createFile(googleApiClient, changeSet, contents).await();
        return fileResult.getStatus();
    } else {
        return contentsResultStatus;
    }
}
 
Example 3
Source File: AutoCompleteAdapter.java    From AutocompleteLocation with Apache License 2.0 6 votes vote down vote up
private ArrayList<AutocompletePrediction> getAutocomplete(CharSequence constraint) {
  if (mGoogleApiClient.isConnected()) {
    PendingResult<AutocompletePredictionBuffer> results =
        Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
            mBounds, mPlaceFilter);

    AutocompletePredictionBuffer autocompletePredictions = results.await(60, TimeUnit.SECONDS);

    final Status status = autocompletePredictions.getStatus();
    if (!status.isSuccess()) {
      Toast.makeText(getContext(), "Error contacting API: " + status.toString(),
          Toast.LENGTH_SHORT).show();
      autocompletePredictions.release();
      return null;
    }

    return DataBufferUtils.freezeAndClose(autocompletePredictions);
  }
  return null;
}
 
Example 4
Source File: MainActivity.java    From nearby-beacons with MIT License 6 votes vote down vote up
@Override
public void onResult(@NonNull Status status) {
    if (status.isSuccess()) {
        Log.i(TAG, "Permission status succeeded.");
        if (runOnSuccess != null) {
            runOnSuccess.run();
        }
    } else {
        // Currently, the only resolvable error is that the device is not opted
        // in to Nearby. Starting the resolution displays an opt-in dialog.
        if (status.hasResolution()) {
            try {
                status.startResolutionForResult(MainActivity.this,
                        REQUEST_RESOLVE_ERROR);
            } catch (IntentSender.SendIntentException e) {
                showToastAndLog(Log.ERROR, "Request failed with exception: " + e);
            }
        } else {
            showToastAndLog(Log.ERROR, "Request failed with : " + status);
        }
    }
}
 
Example 5
Source File: SecondActivity.java    From journaldev with MIT License 6 votes vote down vote up
@Override
public void onResult(@NonNull CredentialRequestResult credentialRequestResult) {

    Status status = credentialRequestResult.getStatus();
    if (status.isSuccess()) {
        onCredentialSuccess(credentialRequestResult.getCredential());
    } else {
        if (status.hasResolution()) {
            try {
                status.startResolutionForResult(this, RC_REQUEST);
            } catch (IntentSender.SendIntentException e) {
                Log.d(TAG, e.toString());
            }
        } else {
            showToast("Request Failed");
        }
    }
}
 
Example 6
Source File: CreateRouteRequest.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onResult(Cast.ApplicationConnectionResult result) {
    if (mState != STATE_LAUNCHING_APPLICATION
            && mState != STATE_API_CONNECTION_SUSPENDED) {
        throwInvalidState();
    }

    Status status = result.getStatus();
    if (!status.isSuccess()) {
        Log.e(TAG, "Launch application failed with status: %s, %d, %s",
                mSource.getApplicationId(), status.getStatusCode(), status.getStatusMessage());
        reportError();
        return;
    }

    mState = STATE_LAUNCH_SUCCEEDED;
    reportSuccess(result);
}
 
Example 7
Source File: NearbySubscription.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onResult(final Status status) {
    if (status.isSuccess()) {
        Log.d(TAG, "Nearby " + mAction + " succeeded");
    } else {
        Log.d(TAG, "Nearby " + mAction + " failed: " + status.getStatusMessage());
    }
}
 
Example 8
Source File: FitResultCallback.java    From android-play-games-in-motion with Apache License 2.0 5 votes vote down vote up
private void onSensorResult(Status status) {
    if (status.isSuccess()) {
        // There is a lapse between this callback to actually getting data from the listener,
        // depending on the data type. It is a known issue, by design. You can account for that
        // delay with display text or other mechanisms.
        mGoogleApiClient.sensorRegistered(mDataType);
        Utils.logDebug(TAG, "Successfully registered sensor for " + mDataType.toString());
    } else {
        Utils.logDebug(TAG, "There was a problem registering ." + mDataType + "\n" +
                status.getStatusMessage());
    }

}
 
Example 9
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
private void addStepDataToGoogleFit() {
    //Adds steps spread out evenly from start time to end time
    Calendar cal = Calendar.getInstance();
    Date now = new Date();
    cal.setTime(now);
    long endTime = cal.getTimeInMillis();
    cal.add(Calendar.HOUR_OF_DAY, -1);
    long startTime = cal.getTimeInMillis();

    DataSource dataSource = new DataSource.Builder()
            .setAppPackageName(this)
            .setDataType(DataType.TYPE_STEP_COUNT_DELTA)
            .setName("Step Count")
            .setType(DataSource.TYPE_RAW)
            .build();

    int stepCountDelta = 1000000;
    DataSet dataSet = DataSet.create(dataSource);

    DataPoint point = dataSet.createDataPoint()
            .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS);
    point.getValue(Field.FIELD_STEPS).setInt(stepCountDelta);
    dataSet.add(point);

    Status status = Fitness.HistoryApi.insertData(mGoogleApiClient, dataSet).await(1, TimeUnit.MINUTES);

    if (!status.isSuccess()) {
        Log.e( "History", "Problem with inserting data: " + status.getStatusMessage());
    } else {
        Log.e( "History", "data inserted" );
    }
}
 
Example 10
Source File: FitResultCallback.java    From android-play-games-in-motion with Apache License 2.0 5 votes vote down vote up
private void onRecordingUnsubscription(Status status) {
    if (status.isSuccess()) {
        Utils.logDebug(TAG, "Stopped recording data for " + mDataType);
    } else {
        Utils.logDebug(TAG, "Unable to stop recording data for " + mDataType);
    }
}
 
Example 11
Source File: MainActivity.java    From nearby-beacons with MIT License 5 votes vote down vote up
@Override
public void onResult(@NonNull Status status) {
    //Validate if we were able to register for background scans
    if (status.isSuccess()) {
        Log.d(TAG, "Background Register Success!");
    } else {
        Log.w(TAG, "Background Register Error ("
                + status.getStatusCode() + "): "
                + status.getStatusMessage());
    }
}
 
Example 12
Source File: NearbySubscription.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onResult(final Status status) {
    if (status.isSuccess()) {
        Log.d(TAG, "Nearby " + mAction + " succeeded");
    } else {
        Log.d(TAG, "Nearby " + mAction + " failed: " + status.getStatusMessage());
    }
}
 
Example 13
Source File: MainActivity.java    From io2015-codelabs with Apache License 2.0 5 votes vote down vote up
public void onResult(Status status) {
    if (status.isSuccess()) {
        Toast.makeText(
                this,
                "Geofences Added",
                Toast.LENGTH_SHORT
        ).show();
    } else {
        // Get the status code for the error and log it using a user-friendly message.
        String errorMessage = GeofenceErrorMessages.getErrorString(this,
                status.getStatusCode());
    }
}
 
Example 14
Source File: FenceChooserActivity.java    From JCVD with MIT License 5 votes vote down vote up
@Override
public void fenceRemoveStatus(String geofenceId, Status status) {
    if (status.isSuccess()) {
        Toast.makeText(this, "Geofence " + geofenceId + " has been removed", Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(this, "Error when removing " + geofenceId + " : " + status.getStatusMessage(), Toast.LENGTH_SHORT).show();
    }
}
 
Example 15
Source File: FenceChooserActivity.java    From JCVD with MIT License 5 votes vote down vote up
@Override
public void fenceAddStatus(StorableFence fence, Status status) {
    if (fence != null) {
        if (status.isSuccess()) {
            Toast.makeText(this, "Geofence " + fence.getId() + " has been added", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(this, "Error when adding " + fence.getId() + " : " + status.getStatusMessage(), Toast.LENGTH_SHORT).show();
        }
    }
}
 
Example 16
Source File: FitResultCallback.java    From android-play-games-in-motion with Apache License 2.0 5 votes vote down vote up
private void onSessionUnsubscription(Status status) {
    if (status.isSuccess()) {
        Utils.logDebug(TAG, "Ended data session.");
    } else {
        Utils.logDebug(TAG, "Unable to end data session.");
    }
}
 
Example 17
Source File: PlaceAutocompleteAdapter.java    From Airbnb-Android-Google-Map-View with MIT License 4 votes vote down vote up
/**
     * Submits an autocomplete query to the Places Geo Data Autocomplete API.
     * objects to store the Place ID and description that the API returns.
     * Returns an empty list if no results were found.
     * Returns null if the API client is not available or the query did not complete
     * successfully.
     * This method MUST be called off the main UI thread, as it will block until data is returned
     * from the API, which may include a network request.
     *
     * @param constraint Autocomplete query string
     * @return Results from the autocomplete API or null if the query was not successful.
     * @see Places#GEO_DATA_API#getAutocomplete(CharSequence)
     */
    private ArrayList<PlaceAutocomplete> getAutocomplete(CharSequence constraint) {
        if (mGoogleApiClient.isConnected()) {

            // Submit the query to the autocomplete API and retrieve a PendingResult that will
            // contain the results when the query completes.
            PendingResult<AutocompletePredictionBuffer> results =
                    Places.GeoDataApi
                            .getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
                                    mBounds, mPlaceFilter);

            // This method should have been called off the main UI thread. Block and wait for at most 60s
            // for a result from the API.
            AutocompletePredictionBuffer autocompletePredictions = results
                    .await(60, TimeUnit.SECONDS);

            // Confirm that the query completed successfully, otherwise return null
            final Status status = autocompletePredictions.getStatus();
            if (!status.isSuccess()) {
                autocompletePredictions.release();
                return null;
            }

            //Log.i(TAG, "Query completed. Received " + autocompletePredictions.getCount()
            //           + " predictions.");
//
            // Copy the results into our own data structure, because we can't hold onto the buffer.
            // AutocompletePrediction objects encapsulate the API response (place ID and description).

            Iterator<AutocompletePrediction> iterator = autocompletePredictions.iterator();
            ArrayList resultList = new ArrayList<>(autocompletePredictions.getCount());
            while (iterator.hasNext()) {
                AutocompletePrediction prediction = iterator.next();
                // Get the details of this prediction and copy it into a new PlaceAutocomplete object.
                resultList.add(new PlaceAutocomplete(prediction.getPlaceId(),
                        prediction.getDescription()));
            }

            // Release the buffer now that all data has been copied.
            autocompletePredictions.release();
            return resultList;
        }
        //Log.e(TAG, "Google API client is not connected for autocomplete query.");
        return null;
    }
 
Example 18
Source File: PlacesAutoCompleteAdapter.java    From GoogleAutoCompleteWithRecyclerView with GNU General Public License v2.0 4 votes vote down vote up
private ArrayList<PlaceAutocomplete> getAutocomplete(CharSequence constraint) {
    if (mGoogleApiClient.isConnected()) {
        Log.i("", "Starting autocomplete query for: " + constraint);

        // Submit the query to the autocomplete API and retrieve a PendingResult that will
        // contain the results when the query completes.
        PendingResult<AutocompletePredictionBuffer> results =
                Places.GeoDataApi
                        .getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
                                mBounds, mPlaceFilter);

        // This method should have been called off the main UI thread. Block and wait for at most 60s
        // for a result from the API.
        AutocompletePredictionBuffer autocompletePredictions = results
                .await(60, TimeUnit.SECONDS);

        // Confirm that the query completed successfully, otherwise return null
        final Status status = autocompletePredictions.getStatus();
        if (!status.isSuccess()) {
            Toast.makeText(mContext, "Error contacting API: " + status.toString(),
                    Toast.LENGTH_SHORT).show();
            Log.e("", "Error getting autocomplete prediction API call: " + status.toString());
            autocompletePredictions.release();
            return null;
        }

        Log.i("", "Query completed. Received " + autocompletePredictions.getCount()
                + " predictions.");

        // Copy the results into our own data structure, because we can't hold onto the buffer.
        // AutocompletePrediction objects encapsulate the API response (place ID and description).

        Iterator<AutocompletePrediction> iterator = autocompletePredictions.iterator();
        ArrayList resultList = new ArrayList<>(autocompletePredictions.getCount());
        while (iterator.hasNext()) {
            AutocompletePrediction prediction = iterator.next();
            // Get the details of this prediction and copy it into a new PlaceAutocomplete object.
            resultList.add(new PlaceAutocomplete(prediction.getPlaceId(),
                    prediction.getDescription()));
        }

        // Release the buffer now that all data has been copied.
        autocompletePredictions.release();

        return resultList;
    }
    Log.e("", "Google API client is not connected for autocomplete query.");
    return null;
}
 
Example 19
Source File: StatusErrorResultCallBack.java    From RxGps with Apache License 2.0 4 votes vote down vote up
@Override
public void onResult(@NonNull Status status) {
    if (!status.isSuccess()) {
        emitter.onError(new StatusException(status));
    }
}
 
Example 20
Source File: HARecognizerApiHandler.java    From DataLogger with MIT License 2 votes vote down vote up
/**
 * Runs when the result of calling requestActivityUpdates() and removeActivityUpdates() becomes
 * available. Either method can complete successfully or with an error.
 *
 * @param status The Status returned through a PendingIntent when requestActivityUpdates()
 *               or removeActivityUpdates() are called.
 */
public void onResult(Status status) {
    if (!status.isSuccess()) {
        Log.e(TAG, "Error adding or removing activity detection: " + status.getStatusMessage());
    }
}