I want to get the exceptions caused when a user fails to log into my app using Google Sign in. For example, in the handleSignInResult(@NonNull Task<GoogleSignInAccount> completedTask) method I use this:
private void handleSignInResult(@NonNull Task<GoogleSignInAccount> completedTask) { try { account = completedTask.getResult(ApiException.class); if(isSignedIn()) { Toast.makeText(this, "Success!", Toast.LENGTH_SHORT).show(); startActivity(new Intent(MainActivity.this, Home.class)); } } catch (ApiException e) { Toast.make(this, "Failed to login because: " + e.getCause(), Toast.LENGTH_LONG).show(); } } } This helps me to get the cause of the error. But the most common cause is that when when no account is selected, this code returns null.
But I want to make a Toast when no account is selcted:
Toast.makeText(this, "Failed to login because: No account selected!", Toast.LENGTH_LONG).show(); I think that this can be achieved using the switch case but I don't know how to do that.
if(e.getCause() != null){Toast.make(this, "Failed to login because: " + e.getCause(), Toast.LENGTH_LONG).show();}else{ Toast.make(this, "Failed to login because: No account selected!", Toast.LENGTH_LONG).show();}catch