Android:如何获取用户的性别和年龄?

我有一个 Android 应用,我想根据用户的性别和年龄自动设置.

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

获取用户年龄和性别的方法有哪些?(符合 Google Play 政策)

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

例如,有没有办法通过 Google Play Services 获取这些信息?

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

谢谢.

推荐答案

你应该使用 interface Person,您将拥有您需要了解的有关用户的所有信息.(通过getGender()getBirthday()(或getAgeRange())

例如使用 getGender(),你可以围绕这个做一些事情:

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();

相关文章