Yes it is possible, and it is quiet simple. Before you start you need to add, one permission to you AndroidManifest.xml
<uses-permission android:name="android.permission.GET_ACCOUNTS"></uses-permission>
It allows you to read the accounts associated with the device. Then you do the following inside the app:
Account[] accounts = AccountManager.get(context).getAccountsByType("com.google");
This will return all google accounts of the user. In your case maybe you need only the emails, so here is a quick static function that will give them to you:
public static String[] getAccounts(Context context) {
Account[] accounts = AccountManager.get(context).getAccountsByType("com.google");
String[] names = new String[accounts.length];
for (int i = 0; i < accounts.length; ++i) names[i] = accounts[i].name;
return names;
}
This function will return a string array of all gmail emails (Google accounts) on the device.
However, if you need to "talk" with some Google services for some more information, you will have to do the following. First add one more permission to the manifest:
<uses-permission android:name="android.permission.USE_CREDENTIALS"></uses-permission>
This permission will allow your app to use the use credentials to identify the user in front of some Google service. It will NOT give you the credentials(passwords).
To use some Google service you will need a token. Here it is a quick function for that:
public static String getToken(Activity activity, String serviceName) {
try {
Bundle result = AccountManager.get(activity).getAuthToken(account, serviceName, null, activity, null, null).getResult();
return result.getString(AccountManager.KEY_AUTHTOKEN);
} catch (OperationCanceledException e) {
Log.d("Test", "Operation Canceled");
} catch (AuthenticatorException e) {
Log.d("Test", "Authenticator Exception");
} catch (IOException e) {
Log.d("Test", "Auth IOException");
}
return null;
}
Once you have the token you just the HTTP API they have and you have fun :-)