com.google.android.gms.common.api.ApiException Java Examples

The following examples show how to use com.google.android.gms.common.api.ApiException. 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: LoginActivity.java    From TwrpBuilder with GNU General Public License v3.0 9 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == 1) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            GoogleSignInAccount account = task.getResult(ApiException.class);
            firebaseAuthWithGoogle(account);
        } catch (ApiException e) {
            Log.w("TAG", "Google sign in failed", e);
            // ...
        }
    }
}
 
Example #2
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 8 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
  super.onActivityResult(requestCode, resultCode, intent);
  if (requestCode == RC_SIGN_IN) {
    Task<GoogleSignInAccount> task =
        GoogleSignIn.getSignedInAccountFromIntent(intent);

    try {
      GoogleSignInAccount account = task.getResult(ApiException.class);
      onConnected(account);
    } catch (ApiException apiException) {
      String message = apiException.getMessage();
      if (message == null || message.isEmpty()) {
        message = getString(R.string.signin_other_error);
      }

      onDisconnected();

      new AlertDialog.Builder(this)
          .setMessage(message)
          .setNeutralButton(android.R.string.ok, null)
          .show();
    }
  }
}
 
Example #3
Source File: SignInActivity.java    From codelab-friendlychat-android with Apache License 2.0 8 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent in signIn()
    if (requestCode == RC_SIGN_IN) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = task.getResult(ApiException.class);
            firebaseAuthWithGoogle(account);
        } catch (ApiException e) {
            // Google Sign In failed, update UI appropriately
            Log.w(TAG, "Google sign in failed", e);
        }
    }
}
 
Example #4
Source File: MainActivity.java    From Android-9-Development-Cookbook with MIT License 8 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == REQUEST_SIGN_IN) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            GoogleSignInAccount account = task.getResult(ApiException.class);
            findViewById(R.id.signInButton).setVisibility(View.GONE);
            Toast.makeText(this, "Logged in:"+account.getDisplayName(), Toast.LENGTH_SHORT)
                    .show();
        } catch (ApiException e) {
            e.printStackTrace();
            Toast.makeText(this, "Sign in failed:"+e.getLocalizedMessage(), Toast.LENGTH_SHORT)
                    .show();
        }
    }
}
 
Example #5
Source File: PurchaseActivity.java    From YTPlayer with GNU General Public License v3.0 8 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    if (requestCode == RC_SIGN_IN) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            GoogleSignInAccount account = task.getResult(ApiException.class);
            firebaseAuthWithGoogle(account);
        } catch (ApiException e) {
            Toast.makeText(this, "Failed to sign in, Error: "+e.getStatusCode(), Toast.LENGTH_SHORT).show();
            e.printStackTrace();
            Log.e(TAG, "signInResult:failed code=" + e.getStatusCode());
        }
    }
    if (requestCode == 104) {
        if (resultCode==1) {
            boolean isPaid = data.getBooleanExtra("payment",false);
            if (isPaid) {
                setSuccess(data.getStringExtra("client"),
                        FirebaseDatabase.getInstance().getReference("orders"));
            }
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}
 
Example #6
Source File: LoginActivity.java    From triviums with MIT License 8 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = task.getResult(ApiException.class);
            firebaseAuthWithGoogle(account);
        } catch (ApiException e) {
            // Google Sign In failed, update UI appropriately
            Log.w("TAG", "Google sign in failed", e);
        }

    }
}
 
Example #7
Source File: AuthenticationManager.java    From ground-android with Apache License 2.0 7 votes vote down vote up
private void onActivityResult(ActivityResult activityResult) {
  // The Task returned from getSignedInAccountFromIntent is always completed, so no need to
  // attach a listener.
  try {
    Task<GoogleSignInAccount> googleSignInTask =
        GoogleSignIn.getSignedInAccountFromIntent(activityResult.getData());
    onGoogleSignIn(googleSignInTask.getResult(ApiException.class));
  } catch (ApiException e) {
    Log.w(TAG, "Sign in failed: " + e);
    signInState.onNext(new SignInState(e));
  }
}
 
Example #8
Source File: SignInActivity.java    From budgetto with MIT License 7 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_SIGN_IN) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            GoogleSignInAccount account = task.getResult(ApiException.class);
            firebaseAuthWithGoogle(account);
        } catch (ApiException e) {
            e.printStackTrace();
            hideProgressView();
            loginError("Google sign in failed.");
        }
    }
}
 
Example #9
Source File: GoogleAccountsProvider.java    From science-journal with Apache License 2.0 7 votes vote down vote up
@Override
public void onLoginAccountsChanged(Intent data) {
  try {
    Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
    GoogleSignInAccount account = task.getResult(ApiException.class);
    GoogleSignInAccount googleSignInAccount = GoogleSignIn.getLastSignedInAccount(context);
    signInCurrentAccount(googleSignInAccount);
  } catch (ApiException apiException) {
    Log.e(TAG, "GoogleSignIn api exception");
  }
}
 
Example #10
Source File: SettingsFragment.java    From YTPlayer with GNU General Public License v3.0 7 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode==103) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            GoogleSignInAccount account = task.getResult(ApiException.class);
            firebaseAuthWithGoogle(account);
        } catch (ApiException e) {
            Toast.makeText(activity, "Failed to sign in, Error: "+e.getStatusCode(), Toast.LENGTH_SHORT).show();
            e.printStackTrace();
            Log.e(TAG, "signInResult:failed code=" + e.getStatusCode());
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}
 
Example #11
Source File: GameSyncService.java    From Passbook with Apache License 2.0 7 votes vote down vote up
@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
    if(requestCode == CA.AUTH) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            mSignInAccount = task.getResult(ApiException.class);
            mSnapshotClient = Games.getSnapshotsClient(activity, mSignInAccount);
            mListener.onSyncProgress(CA.AUTH);
            read();
        } catch (ApiException e) {
            mListener.onSyncFailed(CA.CONNECTION);
        }
    }
}
 
Example #12
Source File: SkeletonActivity.java    From android-basic-samples with Apache License 2.0 7 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {

  if (requestCode == RC_SIGN_IN) {

    Task<GoogleSignInAccount> task =
        GoogleSignIn.getSignedInAccountFromIntent(intent);

    try {
      GoogleSignInAccount account = task.getResult(ApiException.class);
      onConnected(account);
    } catch (ApiException apiException) {
      String message = apiException.getMessage();
      if (message == null || message.isEmpty()) {
        message = getString(R.string.signin_other_error);
      }

      onDisconnected();

      new AlertDialog.Builder(this)
          .setMessage(message)
          .setNeutralButton(android.R.string.ok, null)
          .show();
    }
  } else if (requestCode == RC_LOOK_AT_MATCHES) {
    // Returning from the 'Select Match' dialog

    if (resultCode != Activity.RESULT_OK) {
      logBadActivityResult(requestCode, resultCode,
          "User cancelled returning from the 'Select Match' dialog.");
      return;
    }

    TurnBasedMatch match = intent
        .getParcelableExtra(Multiplayer.EXTRA_TURN_BASED_MATCH);

    if (match != null) {
      updateMatch(match);
    }

    Log.d(TAG, "Match = " + match);
  } else if (requestCode == RC_SELECT_PLAYERS) {
    // Returning from 'Select players to Invite' dialog

    if (resultCode != Activity.RESULT_OK) {
      // user canceled
      logBadActivityResult(requestCode, resultCode,
          "User cancelled returning from 'Select players to Invite' dialog");
      return;
    }

    // get the invitee list
    ArrayList<String> invitees = intent
        .getStringArrayListExtra(Games.EXTRA_PLAYER_IDS);

    // get automatch criteria
    Bundle autoMatchCriteria;

    int minAutoMatchPlayers = intent.getIntExtra(Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0);
    int maxAutoMatchPlayers = intent.getIntExtra(Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 0);

    if (minAutoMatchPlayers > 0) {
      autoMatchCriteria = RoomConfig.createAutoMatchCriteria(minAutoMatchPlayers,
          maxAutoMatchPlayers, 0);
    } else {
      autoMatchCriteria = null;
    }

    TurnBasedMatchConfig tbmc = TurnBasedMatchConfig.builder()
        .addInvitedPlayers(invitees)
        .setAutoMatchCriteria(autoMatchCriteria).build();

    // Start the match
    mTurnBasedMultiplayerClient.createMatch(tbmc)
        .addOnSuccessListener(new OnSuccessListener<TurnBasedMatch>() {
          @Override
          public void onSuccess(TurnBasedMatch turnBasedMatch) {
            onInitiateMatch(turnBasedMatch);
          }
        })
        .addOnFailureListener(createFailureListener("There was a problem creating a match!"));
    showSpinner();
  }
}
 
Example #13
Source File: NearbyConnectionModule.java    From react-native-google-nearby-connection with MIT License 6 votes vote down vote up
@ReactMethod
public void acceptConnection(final String serviceId, final String endpointId) {
	final Endpoint endpoint = mEndpoints.get(serviceId+"_"+endpointId);

	logV("acceptConnection(serviceId: "+serviceId+", endpointId:" + endpointId+")");
	final ConnectionsClient clientSingleton = getConnectionsClientSingleton(serviceId);

	clientSingleton
		.acceptConnection(endpointId, getPayloadCallback(serviceId))
		.addOnFailureListener(
			new OnFailureListener() {
				@Override
				public void onFailure(@NonNull Exception e) {
					ApiException apiException = (ApiException) e;

					logW("acceptConnection(serviceId: "+serviceId+", endpointId:" + endpointId+") failed.", e);
				}
			});
}
 
Example #14
Source File: PlaceDetailsActivity.java    From android-places-demos with Apache License 2.0 6 votes vote down vote up
private void getPlaceById() {
    // [START maps_places_get_place_by_id]
    // Define a Place ID.
    final String placeId = "INSERT_PLACE_ID_HERE";

    // Specify the fields to return.
    final List<Place.Field> placeFields = Arrays.asList(Place.Field.ID, Place.Field.NAME);

    // Construct a request object, passing the place ID and fields array.
    final FetchPlaceRequest request = FetchPlaceRequest.newInstance(placeId, placeFields);

    placesClient.fetchPlace(request).addOnSuccessListener((response) -> {
        Place place = response.getPlace();
        Log.i(TAG, "Place found: " + place.getName());
    }).addOnFailureListener((exception) -> {
        if (exception instanceof ApiException) {
            final ApiException apiException = (ApiException) exception;
            Log.e(TAG, "Place not found: " + exception.getMessage());
            final int statusCode = apiException.getStatusCode();
            // TODO: Handle error with given status code.
        }
    });
    // [END maps_places_get_place_by_id]
}
 
Example #15
Source File: NearbyConnectionModule.java    From react-native-google-nearby-connection with MIT License 6 votes vote down vote up
@ReactMethod
public void rejectConnection(final String serviceId, final String endpointId) {
	final Endpoint endpoint = mEndpoints.get(serviceId+"_"+endpointId);

	logV("rejecting connection from " + endpointId);
	final ConnectionsClient clientSingleton = getConnectionsClientSingleton(serviceId);

	clientSingleton
		.rejectConnection(endpointId)
		.addOnFailureListener(
			new OnFailureListener() {
				@Override
				public void onFailure(@NonNull Exception e) {
					ApiException apiException = (ApiException) e;

					logW("rejectConnection() failed.", e);
				}
			});
}
 
Example #16
Source File: ServerAuthCodeActivity.java    From google-services with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RC_GET_AUTH_CODE) {
        // [START get_auth_code]
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            GoogleSignInAccount account = task.getResult(ApiException.class);
            String authCode = account.getServerAuthCode();

            // Show signed-un UI
            updateUI(account);

            // TODO(developer): send code to server and exchange for access/refresh/ID tokens
        } catch (ApiException e) {
            Log.w(TAG, "Sign-in failed", e);
            updateUI(null);
        }
        // [END get_auth_code]
    }
}
 
Example #17
Source File: RestApiActivity.java    From google-services with Apache License 2.0 6 votes vote down vote up
private void handleSignInResult(@NonNull Task<GoogleSignInAccount> completedTask) {
    Log.d(TAG, "handleSignInResult:" + completedTask.isSuccessful());

    try {
        GoogleSignInAccount account = completedTask.getResult(ApiException.class);
        updateUI(account);

        // Store the account from the result
        mAccount = account.getAccount();

        // Asynchronously access the People API for the account
        getContacts();
    } catch (ApiException e) {
        Log.w(TAG, "handleSignInResult:error", e);

        // Clear the local account
        mAccount = null;

        // Signed out, show unauthenticated UI.
        updateUI(null);
    }
}
 
Example #18
Source File: GoogleProviderHandler.java    From capacitor-firebase-auth with MIT License 6 votes vote down vote up
@Override
public void handleOnActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(GOOGLE_TAG, "Google SignIn activity result.");

    try {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        // Google Sign In was successful, authenticate with Firebase
        GoogleSignInAccount account = task.getResult(ApiException.class);

        if (account != null) {
            Log.d(GOOGLE_TAG, "Google Sign In succeed.");
            AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
            this.plugin.handleAuthCredentials(credential);
            return;
        }
    } catch (ApiException exception) {
        // Google Sign In failed, update UI appropriately
        Log.w(GOOGLE_TAG, GoogleSignInStatusCodes.getStatusCodeString(exception.getStatusCode()), exception);
        plugin.handleFailure("Google Sign In failure.", exception);
        return;
    }

    plugin.handleFailure("Google Sign In failure.", null);
}
 
Example #19
Source File: GoogleSignInListenerTest.java    From gdx-fireapp with Apache License 2.0 6 votes vote down vote up
@Test
public void onActivityResult_validRequestCode_apiException() throws Throwable {
    // Given
    FuturePromise promise = Mockito.mock(FuturePromise.class);
    GoogleSignInListener listener = new GoogleSignInListener(promise);
    Intent intent = PowerMockito.mock(Intent.class);
    int requestCode = Const.GOOGLE_SIGN_IN;
    int resultCode = -1;
    final Task task = Mockito.mock(Task.class);
    Mockito.when(task.getResult(ApiException.class)).then(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            throw new ApiException(Status.RESULT_CANCELED);
        }
    });
    Mockito.when(GoogleSignIn.getSignedInAccountFromIntent(Mockito.any(Intent.class))).thenReturn(task);

    // When
    listener.onActivityResult(requestCode, resultCode, intent);

    // Then
    Mockito.verify(((AndroidApplication) Gdx.app), VerificationModeFactory.times(1)).removeAndroidEventListener(Mockito.refEq(listener));
    Mockito.verify(promise, VerificationModeFactory.times(1)).doFail(Mockito.nullable(Exception.class));
}
 
Example #20
Source File: LoginActivity.java    From NaviBee with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = task.getResult(ApiException.class);
            firebaseAuthWithGoogle(account);
        } catch (ApiException e) {
            // Google Sign In failed
            Toast.makeText(LoginActivity.this, "Sign in fails: " + e.getMessage(), Toast.LENGTH_LONG).show();
        }
    }
}
 
Example #21
Source File: GoogleSignInActivity.java    From quickstart-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = task.getResult(ApiException.class);
            Log.d(TAG, "firebaseAuthWithGoogle:" + account.getId());
            firebaseAuthWithGoogle(account.getIdToken());
        } catch (ApiException e) {
            // Google Sign In failed, update UI appropriately
            Log.w(TAG, "Google sign in failed", e);
            // [START_EXCLUDE]
            updateUI(null);
            // [END_EXCLUDE]
        }
    }
}
 
Example #22
Source File: SafetyNetSampleFragment.java    From android-play-safetynet with Apache License 2.0 6 votes vote down vote up
@Override
public void onFailure(@NonNull Exception e) {
    // An error occurred while communicating with the service.
    mResult = null;

    if (e instanceof ApiException) {
        // An error with the Google Play Services API contains some additional details.
        ApiException apiException = (ApiException) e;
        Log.d(TAG, "Error: " +
                CommonStatusCodes.getStatusCodeString(apiException.getStatusCode()) + ": " +
                apiException.getStatusMessage());
    } else {
        // A different, unknown type of error occurred.
        Log.d(TAG, "ERROR! " + e.getMessage());
    }

}
 
Example #23
Source File: SignInActivity.java    From Duolingo-Clone with MIT License 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RC_SIGN_IN) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {

            GoogleSignInAccount account = task.getResult(ApiException.class);
            firebaseAuthWithGoogle(account);

        } catch (ApiException e) {

            Toast.makeText(context, getString(R.string.auth_failed), Toast.LENGTH_SHORT).show();
        }
    }
}
 
Example #24
Source File: AndroidGoogleAccount.java    From QtAndroidTools with MIT License 6 votes vote down vote up
@Override
public void onComplete(@NonNull Task<GoogleSignInAccount> SignInTask)
{
    boolean signInSuccessfully = true;

    try
    {
        loadSignedInAccountInfo(SignInTask.getResult(ApiException.class));
    }
    catch(ApiException e)
    {
        switch(e.getStatusCode())
        {
            case GoogleSignInStatusCodes.DEVELOPER_ERROR:
                Log.d(TAG, "DEVELOPER_ERROR -> Have you signed your project on Android console?");
                break;
            case GoogleSignInStatusCodes.SIGN_IN_REQUIRED:
                Log.d(TAG, "SIGN_IN_REQUIRED -> You have to signin by select account before use this call");
                break;
        }
        signInSuccessfully = false;
        mGoogleSignInClient = null;
    }

    signedIn(signInSuccessfully);
}
 
Example #25
Source File: SignInActivity.java    From codelab-friendlychat-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent in signIn()
    if (requestCode == RC_SIGN_IN) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = task.getResult(ApiException.class);
            firebaseAuthWithGoogle(account);
        } catch (ApiException e) {
            // Google Sign In failed, update UI appropriately
            Log.w(TAG, "Google sign in failed", e);
        }
    }
}
 
Example #26
Source File: BaseAuthActivity.java    From MangoBloggerAndroidApp with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = task.getResult(ApiException.class);
            firebaseAuthWithGoogle(account);
        } catch (ApiException e) {
            // Google Sign In failed, update UI appropriately
            Log.w(TAG, "Google sign in failed", e);
            // ...
        }
    }
}
 
Example #27
Source File: NearbyConnectionModule.java    From react-native-google-nearby-connection with MIT License 6 votes vote down vote up
/**
 * Sends a {@link Payload} to all currently connected endpoints.
 *
 * @param payload The data you want to send.
 */
protected void sendPayload(final String serviceId, final String endpointId, final Payload payload) {
	final ConnectionsClient clientSingleton = getConnectionsClientSingleton(serviceId);

	clientSingleton
		.sendPayload(endpointId, payload)
		.addOnFailureListener(
			new OnFailureListener() {
				@Override
				public void onFailure(@NonNull Exception e) {
					ApiException apiException = (ApiException) e;

					logW("sendPayload() failed.", e);

					onSendPayloadFailed(serviceId, endpointId, payload, apiException.getStatusCode());
				}
			});
}
 
Example #28
Source File: GeofenceErrorMessages.java    From location-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the error string for a geofencing exception.
 */
public static String getErrorString(Context context, Exception e) {
    if (e instanceof ApiException) {
        return getErrorString(context, ((ApiException) e).getStatusCode());
    } else {
        return context.getResources().getString(R.string.unknown_geofence_error);
    }
}
 
Example #29
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 5 votes vote down vote up
private void handleException(Exception e, String details) {
  int status = 0;

  if (e instanceof ApiException) {
    ApiException apiException = (ApiException) e;
    status = apiException.getStatusCode();
  }

  String message = getString(R.string.status_exception_error, details, status, e);

  new AlertDialog.Builder(MainActivity.this)
      .setMessage(message)
      .setNeutralButton(android.R.string.ok, null)
      .show();
}
 
Example #30
Source File: DriveSyncService.java    From Passbook with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data){
    if (requestCode == CA.AUTH) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            mSignInAccount = task.getResult(ApiException.class);
            mDriveResourceClient = Drive.getDriveResourceClient(activity, mSignInAccount);
            mListener.onSyncProgress(CA.AUTH);
            read();
        } catch (ApiException e) {
            Log.e(LOG_TAG, "onActivityResult: ",  e);
            mListener.onSyncFailed(CA.CONNECTION);
        }
    }
}