0

I am developing application where I need to send invitation mail to users gmail contacts, I come to know android automatically sync gmail and device contact so I have planned to use device contact details to get email addresses now I My problem is how to check whether user have gmail account if yes then its fine but if not app will prompt to create one and sync first.

So please tell me how to check whether user have synchronized gmail account. Is there any better approach?

DCoder
  • 3,486
  • 7
  • 36
  • 68
  • have you checked ??OR still u have some issues – Developer Mar 21 '14 at 06:27
  • no issues, its working properly... Do you know what to do if we want to retrieve all email ids at gmail account. I know this is not related to my original question but if you know any link then it will be gr8. – DCoder Mar 21 '14 at 06:38
  • see this might help you http://stackoverflow.com/questions/3044545/get-contact-info-from-android-contact-picker – Developer Mar 21 '14 at 06:50

1 Answers1

4

From this you can get the user have any Gmail Account in device or not :

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;
  }
}
Developer
  • 6,292
  • 19
  • 55
  • 115