I have got an Android app that I want to auto-setup according the gender and age of the user.
我有一个Android应用,我想根据用户的性别和年龄自动设置。
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 ?
例如,是否存在通过谷歌Play服务获取这些信息的方法?
Thanks.
谢谢。
2 个解决方案
#1
10
You should use the interface Person
, you'll have everything you need to know about the user. (through getGender()
and getBirthday()
(Or getAgeRange()
)
你应该使用接口人,你需要知道关于用户的一切。(通过getGender()和getBirthday()(或getAgeRange())))
Edit : For using for example let's say getGender(), you would do something around this :
编辑:例如,如果使用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();
#2
3
An alternative, perhaps more reliable, approach to guessing your user's gender in Android would be hitting a third party API with the email address of your user, then letting the API look for a first name inside the email string, match it against a database of names, then return to you a gender + confidence level. I used "Gender API" (no affiliation).
的另一种选择,也许更可靠,方法猜测用户的性别在Android触及第三方API与您的用户的电子邮件地址,然后让API寻找一个名字在电子邮件一个字符串,对数据库匹配的名字,然后再回到你性别+信心水平。我使用的是“性别API”(没有从属关系)。
Just have to add to AndroidManifest:
只需要添加AndroidManifest:
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
Then get your user's Gmail addresses:
然后获取用户的Gmail地址:
Pattern pattern = Patterns.EMAIL_ADDRESS;
Account[] accounts = AccountManager.get(context).getAccounts();
for (Account account : accounts) {
if (pattern.matcher(account.name).matches()) {
String emailAddress = account.name
// grab each of your user's email addresses
}
}
Then, if you want to use the API I used, get a key from gender-api.com and hit this link for each email address:
然后,如果你想使用我使用的API,请从gender-api.com上获取一个键,并按一下每个电子邮件地址的链接:
https://gender-api.com/get?email=ANDROID_USER_EMAIL_ADDRESS&key=<YOUR_PRIVATE_KEY>
This API returns gender and level of confidence and I'm sure there are others out there that do the same thing.
这个API返回性别和自信程度,我确信还有其他人也做同样的事情。
#1
10
You should use the interface Person
, you'll have everything you need to know about the user. (through getGender()
and getBirthday()
(Or getAgeRange()
)
你应该使用接口人,你需要知道关于用户的一切。(通过getGender()和getBirthday()(或getAgeRange())))
Edit : For using for example let's say getGender(), you would do something around this :
编辑:例如,如果使用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();
#2
3
An alternative, perhaps more reliable, approach to guessing your user's gender in Android would be hitting a third party API with the email address of your user, then letting the API look for a first name inside the email string, match it against a database of names, then return to you a gender + confidence level. I used "Gender API" (no affiliation).
的另一种选择,也许更可靠,方法猜测用户的性别在Android触及第三方API与您的用户的电子邮件地址,然后让API寻找一个名字在电子邮件一个字符串,对数据库匹配的名字,然后再回到你性别+信心水平。我使用的是“性别API”(没有从属关系)。
Just have to add to AndroidManifest:
只需要添加AndroidManifest:
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
Then get your user's Gmail addresses:
然后获取用户的Gmail地址:
Pattern pattern = Patterns.EMAIL_ADDRESS;
Account[] accounts = AccountManager.get(context).getAccounts();
for (Account account : accounts) {
if (pattern.matcher(account.name).matches()) {
String emailAddress = account.name
// grab each of your user's email addresses
}
}
Then, if you want to use the API I used, get a key from gender-api.com and hit this link for each email address:
然后,如果你想使用我使用的API,请从gender-api.com上获取一个键,并按一下每个电子邮件地址的链接:
https://gender-api.com/get?email=ANDROID_USER_EMAIL_ADDRESS&key=<YOUR_PRIVATE_KEY>
This API returns gender and level of confidence and I'm sure there are others out there that do the same thing.
这个API返回性别和自信程度,我确信还有其他人也做同样的事情。