- Как проверить, вошел ли пользователь в Google или нет. Мне нужно показывать кнопку входа в Google, если она не используется. вошел в систему и другой вид, когда уже авторизовался?
- Как войти новым способом - GetSignInWithGoogleOption
Код: Выделить всё
//here I don't know how to check if user is logged as this method is deprecated (GoogleSignIn)
if (!isSignedIn()) {
relativeLayout1.setVisibility(View.VISIBLE);
relativeLayout2.setVisibility(View.GONE);
} else {
relativeLayout1.setVisibility(View.GONE);
relativeLayout2.setVisibility(View.VISIBLE);
signInWithGoogle();
}
private boolean isSignedIn() {
return GoogleSignIn.getLastSignedInAccount(this) != null && GoogleSignIn.hasPermissions(GoogleSignIn.getLastSignedInAccount(this));
}
//не знаю, зачем мне нужен serverclientID из Webapp, если у меня нет никакого веб-приложения.
Код: Выделить всё
private void signInWithGoogle() {
GetSignInWithGoogleOption googleIdOption = new GetSignInWithGoogleOption.Builder("serverclientID")
.build();
GetCredentialRequest request = new GetCredentialRequest.Builder()
.addCredentialOption(googleIdOption)
.build();
CredentialManager credentialManager = CredentialManager.create(this);
credentialManager.getCredentialAsync(
this,
request,
new CancellationSignal(),
Executors.newSingleThreadExecutor(),
new CredentialManagerCallback() {
@Override
public void onResult(GetCredentialResponse result) {
Credential credential = result.getCredential();
Drive googleDriveService = new Drive.Builder(
AndroidHttp.newCompatibleTransport(),
new GsonFactory(),
(HttpRequestInitializer) credential)
.setApplicationName("MYAPP")
.build();
driveServiceHelper = new DriveServiceHelper(googleDriveService);
RelativeLayout relativeLayout1 = findViewById(R.id.logscreen);
RelativeLayout relativeLayout2 = findViewById(R.id.logmenu);
relativeLayout1.setVisibility(View.GONE);
relativeLayout2.setVisibility(View.VISIBLE);
}
@Override
public void onError(GetCredentialException e) {
// Handle error
}
});
}
Оно заканчивается onError следующим сообщением: GoogleIdTokenCredential невозможно привести к com.google.api.client.http.HttpRequestInitializer
после того, как я выберу свою учетную запись.
Подробнее здесь: https://stackoverflow.com/questions/784 ... leidtokenc
Мобильная версия