If you use a method that does not require a permission request through AndroidManifest.xml
, you can use the Google Play AccountPicker services .
Create a dialog that allows the user to select the desired Google account:
Intent intent = AccountPicker.newChooseAccountIntent(null, null, new String[]{"com.google"}, false, null, null, null, null); startActivityForResult(intent, SOME_REQUEST_CODE);
then process the result in Activity
:
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { if (requestCode == SOME_REQUEST_CODE && resultCode == RESULT_OK) { String emailAddress = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
Remember to add compile 'com.google.android.gms:play-services-identity:8.+'
to the dependencies in your build.gradle
file (check here for the most recent version number used).
source share