Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Google Account Id /username via Android

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 identity of the person submitting the data.

like image 326
KawBoy Avatar asked Feb 11 '10 15:02

KawBoy


1 Answers

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

<uses-permission android:name="android.permission.GET_ACCOUNTS"></uses-permission> <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"></uses-permission> 

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).

like image 150
Fabricio Buzeto Avatar answered Oct 11 '22 13:10

Fabricio Buzeto