Android : how to get the gender and age of the user?

后端 未结 2 656
名媛妹妹
名媛妹妹 2020-12-16 17:07

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 ? (

2条回答
  •  别那么骄傲
    2020-12-16 17:39

    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:

    
    

    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=
    

    This API returns gender and level of confidence and I'm sure there are others out there that do the same thing.

提交回复
热议问题