Android:如何获取用户的性别和年龄?
问题内容:
我有一个要根据用户的性别和年龄自动设置的Android应用。
获取用户年龄和性别的方法有哪些?(符合Google Play政策)
例如,是否可以通过Google Play服务获取这些信息?
谢谢。
问题答案:
您应该使用interface Person
,您将拥有所有需要了解的有关用户的信息。(通过getGender()
和getBirthday()
(或getAgeRange()
)
编辑:例如,假设使用getGender(),您可以在此周围做一些事情:
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();