Accessing Google Account Id /username via Android

后端 未结 7 2283
夕颜
夕颜 2020-11-28 02:11

How do you access the user\'s Google Account Id / username in code? I am building an application that will call a web service to store data and I want to identify the ident

7条回答
  •  伪装坚强ぢ
    2020-11-28 02:26

    I've ran into the same issue and these two links solved for me:

    The first one is this one: How do I retrieve the logged in Google account on android phones?

    Which presents the code for retrieving the accounts associated with the phone. Basically you will need something like this:

    AccountManager manager = (AccountManager) getSystemService(ACCOUNT_SERVICE);
    Account[] list = manager.getAccounts();
    

    And to add the permissions in the AndroidManifest.xml

    
    
    

    Additionally, if you are using the Emulator the following link will help you to set it up with an account : Android Emulator - Trouble creating user accounts

    Basically, it says that you must create an android device based on a API Level and not the SDK Version (like is usually done).

提交回复
热议问题