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 ? (
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();
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).
Just have to add to AndroidManifest:
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
Then get your user's Gmail addresses:
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:
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.