Last active
August 29, 2015 14:09
-
-
Save msomu/3d6273eb90b3eacc493d to your computer and use it in GitHub Desktop.
Get the user Email id without even saying the user.
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
| <uses-permission android:name="android.permission.GET_ACCOUNTS" /> |
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
| public class SplashActivity extends Activity | |
| { | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| String user_mail = "NoMail"; | |
| user_mail = UserEmailFetcher.getEmail(MainActivity.this); | |
| Log.e("SOMU",user_mail); | |
| } | |
| } |
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
| import android.accounts.Account; | |
| import android.accounts.AccountManager; | |
| import android.content.Context; | |
| /** | |
| * Created by msomu on 19/9/14. | |
| * This class is used for getting the Registered E-Mail id on Google Play account. | |
| */ | |
| public class UserEmailFetcher { | |
| static String getEmail(Context context) { | |
| AccountManager accountManager = AccountManager.get(context); | |
| Account account = getAccount(accountManager); | |
| if (account == null) { | |
| return null; | |
| } else { | |
| return account.name; | |
| } | |
| } | |
| private static Account getAccount(AccountManager accountManager) { | |
| Account[] accounts = accountManager.getAccountsByType("com.google"); | |
| Account account; | |
| if (accounts.length > 0) { | |
| account = accounts[0]; | |
| } else { | |
| account = null; | |
| } | |
| return account; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment