Android:如何获得用户的性别和年龄? [英] Android : how to get the gender and age of the user?
问题描述
我有一个Android应用,我想根据用户的性别和年龄进行自动设置。
有什么不同的方式来获得年龄和用户的性别? (符合Google Play政策)
例如,有没有办法通过Google Play服务获取这些信息?
谢谢。
您应该使用 interface Person
,您将拥有你需要知道的关于用户的一切。 (通过 getGender()
和 getBirthday()
(或 getAgeRange()$ c
编辑:
例如,让我们说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。性别性别;
Person personProfile = Plus.PeopleApi.getCurrentPerson(client);
if(person.hasGender())//不保证
gender = person.getGender( );
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.
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();
这篇关于Android:如何获得用户的性别和年龄?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!