Created
July 10, 2013 07:02
-
-
Save aritzg/5964046 to your computer and use it in GitHub Desktop.
AccountUtil
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package net.sareweb.android.lostandfound.util; | |
| import android.accounts.Account; | |
| import android.accounts.AccountManager; | |
| import android.content.Context; | |
| import com.google.android.gms.auth.GoogleAuthUtil; | |
| /** | |
| * Created by aritz on 11/06/13. | |
| */ | |
| public class AccountUtil { | |
| private static String token = null; | |
| public static String getGoogleEmail(Context context) { | |
| AccountManager am = AccountManager.get(context); | |
| Account[] accounts = am.getAccountsByType("com.google"); | |
| if (accounts != null && accounts.length > 0) { | |
| Account account = (Account) accounts[0]; | |
| return account.name; | |
| } else { | |
| return null; | |
| } | |
| } | |
| public static String getGoogleAuthToken(Context context) { | |
| if (token == null) { | |
| try { | |
| token = GoogleAuthUtil.getToken(context, getGoogleEmail(context), "audience:server:client_id:401063832600.apps.googleusercontent.com"); | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| token = null; | |
| } | |
| } | |
| return token; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment