選択したアカウントにこの機能を使用し、ユーザーのメールを取得します。
private void pickUserAccount() {
String[] accountTypes = new String[]{"com.google"};
try { // request account
Intent intent = AccountPicker
.newChooseAccountIntent(null, null, accountTypes, false, null, null, null, null);
startActivityForResult(intent, AuthProcess.REQUEST_CODE_PICK_ACCOUNT);
/*
Error control
*/
} catch (CriticalException e) {
throw e;
} catch (OutOfMemoryError e) { // problems with memory
throw e;
} catch (Throwable e) { // Other exceptions
final String message = "Error during google account picker dialog: " + e;
throw new CriticalException(logcat, message);
}
} // End: pickUserAccount
Android 6.0 では、このコードは、デバイスに 1 つの Google アカウントしか存在しないにもかかわらず、選択したアカウントのダイアログを開きます。Android 4.4.2 ではうまく動作します。どうしたの?ありがとうございました。