Regis_AG Regis_AG - 3 months ago 34
Java Question

Android : how to get the gender and age of the user?

I have got an Android app that I want to auto-setup according the gender and age of the user.

What are the different ways to get the age and the gender of a user ? (which are Google Play policy compliant)

For example, is there a way to get these information through Google Play Services ?

Thanks.

Answer

You should use the interface Person, you'll have everything you need to know about the user. (through getGender() and getBirthday() (Or getAgeRange())

Edit : For using for example let's say getGender(), you would do something around this :

 GoogleApiClient client = new GoogleApiClient.Builder(this)
         .addApi(Plus.API)
         .addScope(Plus.SCOPE_PLUS_LOGIN)
         .setAccountName("users.account.name@gmail.com")
         .build();


client.connect();
Person.Gender gender;
Person personProfile = Plus.PeopleApi.getCurrentPerson(client);

if (person.hasGender()) // it's not guaranteed
          gender = person.getGender();