Search in sources :

Example 16 with ConnectionResult

use of com.google.android.gms.common.ConnectionResult in project Thesis by bajnax.

the class LeScanActivity method enableLocation.

public void enableLocation() {
    if (googleApiClient == null) {
        googleApiClient = new GoogleApiClient.Builder(LeScanActivity.this).addApi(LocationServices.API).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {

            @Override
            public void onConnected(Bundle bundle) {
            }

            @Override
            public void onConnectionSuspended(int i) {
                googleApiClient.connect();
            }
        }).addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {

            @Override
            public void onConnectionFailed(ConnectionResult connectionResult) {
                Log.d("Location error", "Location error " + connectionResult.getErrorCode());
            }
        }).build();
        googleApiClient.connect();
    }
    LocationRequest locationRequest = LocationRequest.create();
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    locationRequest.setInterval(30 * 1000);
    locationRequest.setFastestInterval(5 * 1000);
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
    builder.setAlwaysShow(true);
    PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
    result.setResultCallback(new ResultCallback<LocationSettingsResult>() {

        @Override
        public void onResult(LocationSettingsResult result) {
            final Status status = result.getStatus();
            switch(status.getStatusCode()) {
                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                    try {
                        // requesting to enable Bluetooth
                        status.startResolutionForResult(LeScanActivity.this, REQUEST_ENABLE_LS);
                    } catch (IntentSender.SendIntentException e) {
                    // Ignore the error.
                    }
                    break;
            }
        }
    });
}
Also used : Status(com.google.android.gms.common.api.Status) GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) LocationRequest(com.google.android.gms.location.LocationRequest) LocationSettingsResult(com.google.android.gms.location.LocationSettingsResult) Bundle(android.os.Bundle) LocationSettingsRequest(com.google.android.gms.location.LocationSettingsRequest) ConnectionResult(com.google.android.gms.common.ConnectionResult)

Aggregations

ConnectionResult (com.google.android.gms.common.ConnectionResult)16 GoogleApiClient (com.google.android.gms.common.api.GoogleApiClient)12 Bundle (android.os.Bundle)6 Intent (android.content.Intent)4 SharedPreferences (android.content.SharedPreferences)4 NonNull (android.support.annotation.NonNull)4 Bitmap (android.graphics.Bitmap)3 NotificationManager (android.app.NotificationManager)2 PendingIntent (android.app.PendingIntent)2 Handler (android.os.Handler)2 GoogleSignInOptions (com.google.android.gms.auth.api.signin.GoogleSignInOptions)2 ConnectionCallbacks (com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks)2 OnConnectionFailedListener (com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener)2 Node (com.google.android.gms.wearable.Node)2 PutDataMapRequest (com.google.android.gms.wearable.PutDataMapRequest)2 RemoteIntent (com.google.android.wearable.intent.RemoteIntent)2 SuppressLint (android.annotation.SuppressLint)1 ContentResolver (android.content.ContentResolver)1 Cursor (android.database.Cursor)1 BitmapFactory (android.graphics.BitmapFactory)1