Android:如何获得用户的性别和年龄? [英] Android : how to get the gender and age of the user?

查看:564
本文介绍了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。性别性别;
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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆