用户登录
用户注册

分享至

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

  • 作者: -白娘子-
  • 来源: 51数据库
  • 2022-12-16

问题描述

我有一个 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();
软件
前端设计
程序设计
Java相关