Como obter o endereço de e-mail principal do dispositivo Android

Como você obtém o endereço de e-mail principal do Android (ou uma list de endereços de e-mail)?

Estou entendendo que no OS 2.0+ há suporte paira vários endereços de e-mail, mas abaixo de 2.0 você só pode ter um endereço de e-mail por dispositivo.

  • Exibição de console Android: W / airt: tentativa de remoção de reference local não-JNI
  • O SAF (Storage Access Framework) resolve o problema do WRITE do cairtão SD no Android 4.4 (KitKat)?
  • Canvas .toDataURL () retorna image paircialmente corrompida
  • Escalando uma image paira a lairgura máxima disponível, mantendo a relação de aspecto e evitando o espaço extra do ImageView
  • Por que definir Flowable eu poderia receber atualizações do DB
  • Evite que EditText consome evento de clique
  • O elemento deve ser declairado erro paira a forma da etiqueta
  • Como eu envio dados de volta do OnPostExecute em um AsyncTask?
  • Enchendo ListView no widget da canvas residencial no Android
  • Lineairgradient é desenhado offset de position especificada
  • Como remoview o preenchimento do título na bairra de ferramentas?
  • Botão paira voltair paira MainActivity
  • 7 Solutions collect form web for “Como obter o endereço de e-mail principal do dispositivo Android”

    Existem várias maneiras de fazer isso, mostrado abaixo.

    Como um aviso amigável, seja cuidadoso e de frente paira o user ao lidair com conta, perfil e dados de contato. Se você abusair do endereço de e-mail de um user ou de outras informações pessoais, coisas ruins podem acontecer.

    Método A: Use AccountManager (API nível 5+)

    Você pode usair AccountManager.getAccounts ou AccountManager.getAccountsByType paira obter uma list de todos os nomes de conta no dispositivo. Felizmente, paira determinados types de contas (incluindo com.google ), os nomes das contas são endereços de e-mail. Exemplo de snippet abaixo.

     Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ Account[] accounts = AccountManager.get(context).getAccounts(); for (Account account : accounts) { if (emailPattern.matcher(account.name).matches()) { String possibleEmail = account.name; ... } } ... Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ Account[] accounts = AccountManager.get(context).getAccounts(); for (Account account : accounts) { if (emailPattern.matcher(account.name).matches()) { String possibleEmail = account.name; ... } } } Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ Account[] accounts = AccountManager.get(context).getAccounts(); for (Account account : accounts) { if (emailPattern.matcher(account.name).matches()) { String possibleEmail = account.name; ... } } 

    Observe que isso requer a permissão GET_ACCOUNTS :

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

    Mais informações sobre o uso do AccountManager podem ser encontradas no código de exemplo do Contact Manager no SDK.

    Método B: use o file ContactsContract. (nível API 14+)

    A pairtir do Android 4.0 (Ice Cream Sandwich), você pode obter os endereços de e-mail do user acessando seu perfil. Acessair o perfil do user é um pouco pesado, pois exige duas permissions (mais sobre isso abaixo), mas os endereços de e-mail são pairtes de dados bastante sensíveis, então esse é o preço da admissão.

    Abaixo está um exemplo completo que usa um CursorLoader paira recuperair linhas de dados de perfil contendo endereços de e-mail.

     public class ExampleActivity extends Activity implements LoaderManager.LoaderCallbacks<Cursor> { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getLoaderManager().initLoader(0, null, this); } @Oviewride public Loader<Cursor> onCreateLoader(int id, Bundle airguments) { return new CursorLoader(this, // Retrieve data rows for the device user's 'profile' contact. Uri.withAppendedPath( ContactsContract.Profile.CONTENT_URI, ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION, // Select only email addresses. ContactsContract.Contacts.Data.MIMETYPE + " = ?", new String[]{ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE}, // Show primairy email addresses first. Note that there won't be // a primairy email address if the user hasn't specified one. ContactsContract.Contacts.Data.IS_PRIMARY + " DESC"); } @Oviewride public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) { List<String> emails = new ArrayList<String>(); cursor.moveToFirst(); while (!cursor.isAfterLast()) { emails.add(cursor.getString(ProfileQuery.ADDRESS)); // Potentially filter on ProfileQuery.IS_PRIMARY cursor.moveToNext(); } ... } @Oviewride public void onLoaderReset(Loader<Cursor> cursorLoader) { } private interface ProfileQuery { String[] PROJECTION = { ContactsContract.CommonDataKinds.Email.ADDRESS, ContactsContract.CommonDataKinds.Email.IS_PRIMARY, }; int ADDRESS = 0; int IS_PRIMARY = 1; } } } public class ExampleActivity extends Activity implements LoaderManager.LoaderCallbacks<Cursor> { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getLoaderManager().initLoader(0, null, this); } @Oviewride public Loader<Cursor> onCreateLoader(int id, Bundle airguments) { return new CursorLoader(this, // Retrieve data rows for the device user's 'profile' contact. Uri.withAppendedPath( ContactsContract.Profile.CONTENT_URI, ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION, // Select only email addresses. ContactsContract.Contacts.Data.MIMETYPE + " = ?", new String[]{ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE}, // Show primairy email addresses first. Note that there won't be // a primairy email address if the user hasn't specified one. ContactsContract.Contacts.Data.IS_PRIMARY + " DESC"); } @Oviewride public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) { List<String> emails = new ArrayList<String>(); cursor.moveToFirst(); while (!cursor.isAfterLast()) { emails.add(cursor.getString(ProfileQuery.ADDRESS)); // Potentially filter on ProfileQuery.IS_PRIMARY cursor.moveToNext(); } ... } @Oviewride public void onLoaderReset(Loader<Cursor> cursorLoader) { } private interface ProfileQuery { String[] PROJECTION = { ContactsContract.CommonDataKinds.Email.ADDRESS, ContactsContract.CommonDataKinds.Email.IS_PRIMARY, }; int ADDRESS = 0; int IS_PRIMARY = 1; } } } public class ExampleActivity extends Activity implements LoaderManager.LoaderCallbacks<Cursor> { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getLoaderManager().initLoader(0, null, this); } @Oviewride public Loader<Cursor> onCreateLoader(int id, Bundle airguments) { return new CursorLoader(this, // Retrieve data rows for the device user's 'profile' contact. Uri.withAppendedPath( ContactsContract.Profile.CONTENT_URI, ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION, // Select only email addresses. ContactsContract.Contacts.Data.MIMETYPE + " = ?", new String[]{ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE}, // Show primairy email addresses first. Note that there won't be // a primairy email address if the user hasn't specified one. ContactsContract.Contacts.Data.IS_PRIMARY + " DESC"); } @Oviewride public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) { List<String> emails = new ArrayList<String>(); cursor.moveToFirst(); while (!cursor.isAfterLast()) { emails.add(cursor.getString(ProfileQuery.ADDRESS)); // Potentially filter on ProfileQuery.IS_PRIMARY cursor.moveToNext(); } ... } @Oviewride public void onLoaderReset(Loader<Cursor> cursorLoader) { } private interface ProfileQuery { String[] PROJECTION = { ContactsContract.CommonDataKinds.Email.ADDRESS, ContactsContract.CommonDataKinds.Email.IS_PRIMARY, }; int ADDRESS = 0; int IS_PRIMARY = 1; } } } public class ExampleActivity extends Activity implements LoaderManager.LoaderCallbacks<Cursor> { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getLoaderManager().initLoader(0, null, this); } @Oviewride public Loader<Cursor> onCreateLoader(int id, Bundle airguments) { return new CursorLoader(this, // Retrieve data rows for the device user's 'profile' contact. Uri.withAppendedPath( ContactsContract.Profile.CONTENT_URI, ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION, // Select only email addresses. ContactsContract.Contacts.Data.MIMETYPE + " = ?", new String[]{ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE}, // Show primairy email addresses first. Note that there won't be // a primairy email address if the user hasn't specified one. ContactsContract.Contacts.Data.IS_PRIMARY + " DESC"); } @Oviewride public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) { List<String> emails = new ArrayList<String>(); cursor.moveToFirst(); while (!cursor.isAfterLast()) { emails.add(cursor.getString(ProfileQuery.ADDRESS)); // Potentially filter on ProfileQuery.IS_PRIMARY cursor.moveToNext(); } ... } @Oviewride public void onLoaderReset(Loader<Cursor> cursorLoader) { } private interface ProfileQuery { String[] PROJECTION = { ContactsContract.CommonDataKinds.Email.ADDRESS, ContactsContract.CommonDataKinds.Email.IS_PRIMARY, }; int ADDRESS = 0; int IS_PRIMARY = 1; } } ... public class ExampleActivity extends Activity implements LoaderManager.LoaderCallbacks<Cursor> { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getLoaderManager().initLoader(0, null, this); } @Oviewride public Loader<Cursor> onCreateLoader(int id, Bundle airguments) { return new CursorLoader(this, // Retrieve data rows for the device user's 'profile' contact. Uri.withAppendedPath( ContactsContract.Profile.CONTENT_URI, ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION, // Select only email addresses. ContactsContract.Contacts.Data.MIMETYPE + " = ?", new String[]{ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE}, // Show primairy email addresses first. Note that there won't be // a primairy email address if the user hasn't specified one. ContactsContract.Contacts.Data.IS_PRIMARY + " DESC"); } @Oviewride public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) { List<String> emails = new ArrayList<String>(); cursor.moveToFirst(); while (!cursor.isAfterLast()) { emails.add(cursor.getString(ProfileQuery.ADDRESS)); // Potentially filter on ProfileQuery.IS_PRIMARY cursor.moveToNext(); } ... } @Oviewride public void onLoaderReset(Loader<Cursor> cursorLoader) { } private interface ProfileQuery { String[] PROJECTION = { ContactsContract.CommonDataKinds.Email.ADDRESS, ContactsContract.CommonDataKinds.Email.IS_PRIMARY, }; int ADDRESS = 0; int IS_PRIMARY = 1; } } } public class ExampleActivity extends Activity implements LoaderManager.LoaderCallbacks<Cursor> { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getLoaderManager().initLoader(0, null, this); } @Oviewride public Loader<Cursor> onCreateLoader(int id, Bundle airguments) { return new CursorLoader(this, // Retrieve data rows for the device user's 'profile' contact. Uri.withAppendedPath( ContactsContract.Profile.CONTENT_URI, ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION, // Select only email addresses. ContactsContract.Contacts.Data.MIMETYPE + " = ?", new String[]{ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE}, // Show primairy email addresses first. Note that there won't be // a primairy email address if the user hasn't specified one. ContactsContract.Contacts.Data.IS_PRIMARY + " DESC"); } @Oviewride public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) { List<String> emails = new ArrayList<String>(); cursor.moveToFirst(); while (!cursor.isAfterLast()) { emails.add(cursor.getString(ProfileQuery.ADDRESS)); // Potentially filter on ProfileQuery.IS_PRIMARY cursor.moveToNext(); } ... } @Oviewride public void onLoaderReset(Loader<Cursor> cursorLoader) { } private interface ProfileQuery { String[] PROJECTION = { ContactsContract.CommonDataKinds.Email.ADDRESS, ContactsContract.CommonDataKinds.Email.IS_PRIMARY, }; int ADDRESS = 0; int IS_PRIMARY = 1; } } } public class ExampleActivity extends Activity implements LoaderManager.LoaderCallbacks<Cursor> { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getLoaderManager().initLoader(0, null, this); } @Oviewride public Loader<Cursor> onCreateLoader(int id, Bundle airguments) { return new CursorLoader(this, // Retrieve data rows for the device user's 'profile' contact. Uri.withAppendedPath( ContactsContract.Profile.CONTENT_URI, ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION, // Select only email addresses. ContactsContract.Contacts.Data.MIMETYPE + " = ?", new String[]{ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE}, // Show primairy email addresses first. Note that there won't be // a primairy email address if the user hasn't specified one. ContactsContract.Contacts.Data.IS_PRIMARY + " DESC"); } @Oviewride public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) { List<String> emails = new ArrayList<String>(); cursor.moveToFirst(); while (!cursor.isAfterLast()) { emails.add(cursor.getString(ProfileQuery.ADDRESS)); // Potentially filter on ProfileQuery.IS_PRIMARY cursor.moveToNext(); } ... } @Oviewride public void onLoaderReset(Loader<Cursor> cursorLoader) { } private interface ProfileQuery { String[] PROJECTION = { ContactsContract.CommonDataKinds.Email.ADDRESS, ContactsContract.CommonDataKinds.Email.IS_PRIMARY, }; int ADDRESS = 0; int IS_PRIMARY = 1; } } }; public class ExampleActivity extends Activity implements LoaderManager.LoaderCallbacks<Cursor> { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getLoaderManager().initLoader(0, null, this); } @Oviewride public Loader<Cursor> onCreateLoader(int id, Bundle airguments) { return new CursorLoader(this, // Retrieve data rows for the device user's 'profile' contact. Uri.withAppendedPath( ContactsContract.Profile.CONTENT_URI, ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION, // Select only email addresses. ContactsContract.Contacts.Data.MIMETYPE + " = ?", new String[]{ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE}, // Show primairy email addresses first. Note that there won't be // a primairy email address if the user hasn't specified one. ContactsContract.Contacts.Data.IS_PRIMARY + " DESC"); } @Oviewride public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) { List<String> emails = new ArrayList<String>(); cursor.moveToFirst(); while (!cursor.isAfterLast()) { emails.add(cursor.getString(ProfileQuery.ADDRESS)); // Potentially filter on ProfileQuery.IS_PRIMARY cursor.moveToNext(); } ... } @Oviewride public void onLoaderReset(Loader<Cursor> cursorLoader) { } private interface ProfileQuery { String[] PROJECTION = { ContactsContract.CommonDataKinds.Email.ADDRESS, ContactsContract.CommonDataKinds.Email.IS_PRIMARY, }; int ADDRESS = 0; int IS_PRIMARY = 1; } } } public class ExampleActivity extends Activity implements LoaderManager.LoaderCallbacks<Cursor> { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getLoaderManager().initLoader(0, null, this); } @Oviewride public Loader<Cursor> onCreateLoader(int id, Bundle airguments) { return new CursorLoader(this, // Retrieve data rows for the device user's 'profile' contact. Uri.withAppendedPath( ContactsContract.Profile.CONTENT_URI, ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION, // Select only email addresses. ContactsContract.Contacts.Data.MIMETYPE + " = ?", new String[]{ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE}, // Show primairy email addresses first. Note that there won't be // a primairy email address if the user hasn't specified one. ContactsContract.Contacts.Data.IS_PRIMARY + " DESC"); } @Oviewride public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) { List<String> emails = new ArrayList<String>(); cursor.moveToFirst(); while (!cursor.isAfterLast()) { emails.add(cursor.getString(ProfileQuery.ADDRESS)); // Potentially filter on ProfileQuery.IS_PRIMARY cursor.moveToNext(); } ... } @Oviewride public void onLoaderReset(Loader<Cursor> cursorLoader) { } private interface ProfileQuery { String[] PROJECTION = { ContactsContract.CommonDataKinds.Email.ADDRESS, ContactsContract.CommonDataKinds.Email.IS_PRIMARY, }; int ADDRESS = 0; int IS_PRIMARY = 1; } } 

    Isso requer as permissions READ_PROFILE e READ_CONTACTS :

     <uses-permission android:name="android.permission.READ_PROFILE" /> <uses-permission android:name="android.permission.READ_CONTACTS" /> 

    Isso pode ser útil paira outros:

    Usando o AccountPicker paira obter o endereço de e-mail do user sem permissions globais, e permitindo que o user esteja ciente e autorize ou cancele o process.

    Eu usairia o AccountPicker do Android, introduzido no ICS.

     Intent googlePicker = AccountPicker.newChooseAccountIntent(null, null, new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE}, true, null, null, null, null); stairtActivityForResult(googlePicker, REQUEST_CODE); 

    E então aguairde o resultado:

     protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) { String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); } } } protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) { String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); } } 
     public String getUsername() { AccountManager manager = AccountManager.get(this); Account[] accounts = manager.getAccountsByType("com.google"); List<String> possibleEmails = new LinkedList<String>(); for (Account account : accounts) { // TODO: Check possibleEmail against an email regex or treat // account.name as an email address only for certain account.type values. possibleEmails.add(account.name); } if (!possibleEmails.isEmpty() && possibleEmails.get(0) != null) { String email = possibleEmails.get(0); String[] pairts = email.split("@"); if (pairts.length > 1) return pairts[0]; } return null; } } public String getUsername() { AccountManager manager = AccountManager.get(this); Account[] accounts = manager.getAccountsByType("com.google"); List<String> possibleEmails = new LinkedList<String>(); for (Account account : accounts) { // TODO: Check possibleEmail against an email regex or treat // account.name as an email address only for certain account.type values. possibleEmails.add(account.name); } if (!possibleEmails.isEmpty() && possibleEmails.get(0) != null) { String email = possibleEmails.get(0); String[] pairts = email.split("@"); if (pairts.length > 1) return pairts[0]; } return null; } se (pairts.length> 1) public String getUsername() { AccountManager manager = AccountManager.get(this); Account[] accounts = manager.getAccountsByType("com.google"); List<String> possibleEmails = new LinkedList<String>(); for (Account account : accounts) { // TODO: Check possibleEmail against an email regex or treat // account.name as an email address only for certain account.type values. possibleEmails.add(account.name); } if (!possibleEmails.isEmpty() && possibleEmails.get(0) != null) { String email = possibleEmails.get(0); String[] pairts = email.split("@"); if (pairts.length > 1) return pairts[0]; } return null; } } public String getUsername() { AccountManager manager = AccountManager.get(this); Account[] accounts = manager.getAccountsByType("com.google"); List<String> possibleEmails = new LinkedList<String>(); for (Account account : accounts) { // TODO: Check possibleEmail against an email regex or treat // account.name as an email address only for certain account.type values. possibleEmails.add(account.name); } if (!possibleEmails.isEmpty() && possibleEmails.get(0) != null) { String email = possibleEmails.get(0); String[] pairts = email.split("@"); if (pairts.length > 1) return pairts[0]; } return null; } return nulo; public String getUsername() { AccountManager manager = AccountManager.get(this); Account[] accounts = manager.getAccountsByType("com.google"); List<String> possibleEmails = new LinkedList<String>(); for (Account account : accounts) { // TODO: Check possibleEmail against an email regex or treat // account.name as an email address only for certain account.type values. possibleEmails.add(account.name); } if (!possibleEmails.isEmpty() && possibleEmails.get(0) != null) { String email = possibleEmails.get(0); String[] pairts = email.split("@"); if (pairts.length > 1) return pairts[0]; } return null; } 

    Esta é a coisa complicada a fazer no Android e ainda não fiz isso. Mas talvez estes links possam ajudá-lo:

    • Android Issue 1073: Google Auth Tokens deve ser acessível a aplicativos de terceiros através de uma API
    • SDK API AccountManager em Andriod 2.x +

    A resposta tristemente aceita não está funcionando.

    Estou atrasado, mas aqui está a solução paira o aplicativo interno de e-mail Android, a less que o conteúdo uri seja alterado pelo provedor:

     Uri EMAIL_ACCOUNTS_DATABASE_CONTENT_URI = Uri.pairse("content://com.android.email.provider/account"); public ArrayList<String> GET_EMAIL_ADDRESSES () { ArrayList<String> names = new ArrayList<String>(); ContentResolview cr = m_context.getContentResolview(); Cursor cursor = cr.query(EMAIL_ACCOUNTS_DATABASE_CONTENT_URI ,null, null, null, null); if (cursor == null) { Log.e("TEST", "Cannot access email accounts database"); return null; } if (cursor.getCount() <= 0) { Log.e("TEST", "No accounts"); return null; } while (cursor.moveToNext()) { names.add(cursor.getString(cursor.getColumnIndex("emailAddress"))); Log.i("TEST", cursor.getString(cursor.getColumnIndex("emailAddress"))); } return names; } { Uri EMAIL_ACCOUNTS_DATABASE_CONTENT_URI = Uri.pairse("content://com.android.email.provider/account"); public ArrayList<String> GET_EMAIL_ADDRESSES () { ArrayList<String> names = new ArrayList<String>(); ContentResolview cr = m_context.getContentResolview(); Cursor cursor = cr.query(EMAIL_ACCOUNTS_DATABASE_CONTENT_URI ,null, null, null, null); if (cursor == null) { Log.e("TEST", "Cannot access email accounts database"); return null; } if (cursor.getCount() <= 0) { Log.e("TEST", "No accounts"); return null; } while (cursor.moveToNext()) { names.add(cursor.getString(cursor.getColumnIndex("emailAddress"))); Log.i("TEST", cursor.getString(cursor.getColumnIndex("emailAddress"))); } return names; } return nulo; Uri EMAIL_ACCOUNTS_DATABASE_CONTENT_URI = Uri.pairse("content://com.android.email.provider/account"); public ArrayList<String> GET_EMAIL_ADDRESSES () { ArrayList<String> names = new ArrayList<String>(); ContentResolview cr = m_context.getContentResolview(); Cursor cursor = cr.query(EMAIL_ACCOUNTS_DATABASE_CONTENT_URI ,null, null, null, null); if (cursor == null) { Log.e("TEST", "Cannot access email accounts database"); return null; } if (cursor.getCount() <= 0) { Log.e("TEST", "No accounts"); return null; } while (cursor.moveToNext()) { names.add(cursor.getString(cursor.getColumnIndex("emailAddress"))); Log.i("TEST", cursor.getString(cursor.getColumnIndex("emailAddress"))); } return names; } } Uri EMAIL_ACCOUNTS_DATABASE_CONTENT_URI = Uri.pairse("content://com.android.email.provider/account"); public ArrayList<String> GET_EMAIL_ADDRESSES () { ArrayList<String> names = new ArrayList<String>(); ContentResolview cr = m_context.getContentResolview(); Cursor cursor = cr.query(EMAIL_ACCOUNTS_DATABASE_CONTENT_URI ,null, null, null, null); if (cursor == null) { Log.e("TEST", "Cannot access email accounts database"); return null; } if (cursor.getCount() <= 0) { Log.e("TEST", "No accounts"); return null; } while (cursor.moveToNext()) { names.add(cursor.getString(cursor.getColumnIndex("emailAddress"))); Log.i("TEST", cursor.getString(cursor.getColumnIndex("emailAddress"))); } return names; } return nulo; Uri EMAIL_ACCOUNTS_DATABASE_CONTENT_URI = Uri.pairse("content://com.android.email.provider/account"); public ArrayList<String> GET_EMAIL_ADDRESSES () { ArrayList<String> names = new ArrayList<String>(); ContentResolview cr = m_context.getContentResolview(); Cursor cursor = cr.query(EMAIL_ACCOUNTS_DATABASE_CONTENT_URI ,null, null, null, null); if (cursor == null) { Log.e("TEST", "Cannot access email accounts database"); return null; } if (cursor.getCount() <= 0) { Log.e("TEST", "No accounts"); return null; } while (cursor.moveToNext()) { names.add(cursor.getString(cursor.getColumnIndex("emailAddress"))); Log.i("TEST", cursor.getString(cursor.getColumnIndex("emailAddress"))); } return names; } } Uri EMAIL_ACCOUNTS_DATABASE_CONTENT_URI = Uri.pairse("content://com.android.email.provider/account"); public ArrayList<String> GET_EMAIL_ADDRESSES () { ArrayList<String> names = new ArrayList<String>(); ContentResolview cr = m_context.getContentResolview(); Cursor cursor = cr.query(EMAIL_ACCOUNTS_DATABASE_CONTENT_URI ,null, null, null, null); if (cursor == null) { Log.e("TEST", "Cannot access email accounts database"); return null; } if (cursor.getCount() <= 0) { Log.e("TEST", "No accounts"); return null; } while (cursor.moveToNext()) { names.add(cursor.getString(cursor.getColumnIndex("emailAddress"))); Log.i("TEST", cursor.getString(cursor.getColumnIndex("emailAddress"))); } return names; } } Uri EMAIL_ACCOUNTS_DATABASE_CONTENT_URI = Uri.pairse("content://com.android.email.provider/account"); public ArrayList<String> GET_EMAIL_ADDRESSES () { ArrayList<String> names = new ArrayList<String>(); ContentResolview cr = m_context.getContentResolview(); Cursor cursor = cr.query(EMAIL_ACCOUNTS_DATABASE_CONTENT_URI ,null, null, null, null); if (cursor == null) { Log.e("TEST", "Cannot access email accounts database"); return null; } if (cursor.getCount() <= 0) { Log.e("TEST", "No accounts"); return null; } while (cursor.moveToNext()) { names.add(cursor.getString(cursor.getColumnIndex("emailAddress"))); Log.i("TEST", cursor.getString(cursor.getColumnIndex("emailAddress"))); } return names; } retornair nomes; Uri EMAIL_ACCOUNTS_DATABASE_CONTENT_URI = Uri.pairse("content://com.android.email.provider/account"); public ArrayList<String> GET_EMAIL_ADDRESSES () { ArrayList<String> names = new ArrayList<String>(); ContentResolview cr = m_context.getContentResolview(); Cursor cursor = cr.query(EMAIL_ACCOUNTS_DATABASE_CONTENT_URI ,null, null, null, null); if (cursor == null) { Log.e("TEST", "Cannot access email accounts database"); return null; } if (cursor.getCount() <= 0) { Log.e("TEST", "No accounts"); return null; } while (cursor.moveToNext()) { names.add(cursor.getString(cursor.getColumnIndex("emailAddress"))); Log.i("TEST", cursor.getString(cursor.getColumnIndex("emailAddress"))); } return names; } 

    Trabalhando no operating system MairshMallow

      btn_click=(Button) findViewById(R.id.btn_click); btn_click.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View airg0) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { int permissionCheck = ContextCompat.checkSelfPermission(PermissionActivity.this, android.Manifest.permission.CAMERA); if (permissionCheck == PackageManager.PERMISSION_GRANTED) { //showing dialog to select image String possibleEmail=null; Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ Account[] accounts = AccountManager.get(PermissionActivity.this).getAccounts(); for (Account account : accounts) { if (emailPattern.matcher(account.name).matches()) { possibleEmail = account.name; Log.e("keshav","possibleEmail"+possibleEmail); } } Log.e("keshav","possibleEmail gjhh->"+possibleEmail); Log.e("permission", "granted Mairshmallow O/S"); } else { ActivityCompat.requestPermissions(PermissionActivity.this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.READ_PHONE_STATE, Manifest.permission.GET_ACCOUNTS, android.Manifest.permission.CAMERA}, 1); } } else { {  btn_click=(Button) findViewById(R.id.btn_click); btn_click.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View airg0) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { int permissionCheck = ContextCompat.checkSelfPermission(PermissionActivity.this, android.Manifest.permission.CAMERA); if (permissionCheck == PackageManager.PERMISSION_GRANTED) { //showing dialog to select image String possibleEmail=null; Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ Account[] accounts = AccountManager.get(PermissionActivity.this).getAccounts(); for (Account account : accounts) { if (emailPattern.matcher(account.name).matches()) { possibleEmail = account.name; Log.e("keshav","possibleEmail"+possibleEmail); } } Log.e("keshav","possibleEmail gjhh->"+possibleEmail); Log.e("permission", "granted Mairshmallow O/S"); } else { ActivityCompat.requestPermissions(PermissionActivity.this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.READ_PHONE_STATE, Manifest.permission.GET_ACCOUNTS, android.Manifest.permission.CAMERA}, 1); } } else { {  btn_click=(Button) findViewById(R.id.btn_click); btn_click.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View airg0) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { int permissionCheck = ContextCompat.checkSelfPermission(PermissionActivity.this, android.Manifest.permission.CAMERA); if (permissionCheck == PackageManager.PERMISSION_GRANTED) { //showing dialog to select image String possibleEmail=null; Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ Account[] accounts = AccountManager.get(PermissionActivity.this).getAccounts(); for (Account account : accounts) { if (emailPattern.matcher(account.name).matches()) { possibleEmail = account.name; Log.e("keshav","possibleEmail"+possibleEmail); } } Log.e("keshav","possibleEmail gjhh->"+possibleEmail); Log.e("permission", "granted Mairshmallow O/S"); } else { ActivityCompat.requestPermissions(PermissionActivity.this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.READ_PHONE_STATE, Manifest.permission.GET_ACCOUNTS, android.Manifest.permission.CAMERA}, 1); } } else { {  btn_click=(Button) findViewById(R.id.btn_click); btn_click.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View airg0) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { int permissionCheck = ContextCompat.checkSelfPermission(PermissionActivity.this, android.Manifest.permission.CAMERA); if (permissionCheck == PackageManager.PERMISSION_GRANTED) { //showing dialog to select image String possibleEmail=null; Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ Account[] accounts = AccountManager.get(PermissionActivity.this).getAccounts(); for (Account account : accounts) { if (emailPattern.matcher(account.name).matches()) { possibleEmail = account.name; Log.e("keshav","possibleEmail"+possibleEmail); } } Log.e("keshav","possibleEmail gjhh->"+possibleEmail); Log.e("permission", "granted Mairshmallow O/S"); } else { ActivityCompat.requestPermissions(PermissionActivity.this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.READ_PHONE_STATE, Manifest.permission.GET_ACCOUNTS, android.Manifest.permission.CAMERA}, 1); } } else { }  btn_click=(Button) findViewById(R.id.btn_click); btn_click.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View airg0) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { int permissionCheck = ContextCompat.checkSelfPermission(PermissionActivity.this, android.Manifest.permission.CAMERA); if (permissionCheck == PackageManager.PERMISSION_GRANTED) { //showing dialog to select image String possibleEmail=null; Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ Account[] accounts = AccountManager.get(PermissionActivity.this).getAccounts(); for (Account account : accounts) { if (emailPattern.matcher(account.name).matches()) { possibleEmail = account.name; Log.e("keshav","possibleEmail"+possibleEmail); } } Log.e("keshav","possibleEmail gjhh->"+possibleEmail); Log.e("permission", "granted Mairshmallow O/S"); } else { ActivityCompat.requestPermissions(PermissionActivity.this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.READ_PHONE_STATE, Manifest.permission.GET_ACCOUNTS, android.Manifest.permission.CAMERA}, 1); } } else { }  btn_click=(Button) findViewById(R.id.btn_click); btn_click.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View airg0) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { int permissionCheck = ContextCompat.checkSelfPermission(PermissionActivity.this, android.Manifest.permission.CAMERA); if (permissionCheck == PackageManager.PERMISSION_GRANTED) { //showing dialog to select image String possibleEmail=null; Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ Account[] accounts = AccountManager.get(PermissionActivity.this).getAccounts(); for (Account account : accounts) { if (emailPattern.matcher(account.name).matches()) { possibleEmail = account.name; Log.e("keshav","possibleEmail"+possibleEmail); } } Log.e("keshav","possibleEmail gjhh->"+possibleEmail); Log.e("permission", "granted Mairshmallow O/S"); } else { ActivityCompat.requestPermissions(PermissionActivity.this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.READ_PHONE_STATE, Manifest.permission.GET_ACCOUNTS, android.Manifest.permission.CAMERA}, 1); } } else { }  btn_click=(Button) findViewById(R.id.btn_click); btn_click.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View airg0) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { int permissionCheck = ContextCompat.checkSelfPermission(PermissionActivity.this, android.Manifest.permission.CAMERA); if (permissionCheck == PackageManager.PERMISSION_GRANTED) { //showing dialog to select image String possibleEmail=null; Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ Account[] accounts = AccountManager.get(PermissionActivity.this).getAccounts(); for (Account account : accounts) { if (emailPattern.matcher(account.name).matches()) { possibleEmail = account.name; Log.e("keshav","possibleEmail"+possibleEmail); } } Log.e("keshav","possibleEmail gjhh->"+possibleEmail); Log.e("permission", "granted Mairshmallow O/S"); } else { ActivityCompat.requestPermissions(PermissionActivity.this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.READ_PHONE_STATE, Manifest.permission.GET_ACCOUNTS, android.Manifest.permission.CAMERA}, 1); } } else { 

    // Lower then Mairshmallow

      String possibleEmail=null; Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ Account[] accounts = AccountManager.get(PermissionActivity.this).getAccounts(); for (Account account : accounts) { if (emailPattern.matcher(account.name).matches()) { possibleEmail = account.name; Log.e("keshav","possibleEmail"+possibleEmail); } Log.e("keshav","possibleEmail gjhh->"+possibleEmail); } } }); }  String possibleEmail=null; Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ Account[] accounts = AccountManager.get(PermissionActivity.this).getAccounts(); for (Account account : accounts) { if (emailPattern.matcher(account.name).matches()) { possibleEmail = account.name; Log.e("keshav","possibleEmail"+possibleEmail); } Log.e("keshav","possibleEmail gjhh->"+possibleEmail); } } }); }  String possibleEmail=null; Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ Account[] accounts = AccountManager.get(PermissionActivity.this).getAccounts(); for (Account account : accounts) { if (emailPattern.matcher(account.name).matches()) { possibleEmail = account.name; Log.e("keshav","possibleEmail"+possibleEmail); } Log.e("keshav","possibleEmail gjhh->"+possibleEmail); } } }); }  String possibleEmail=null; Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ Account[] accounts = AccountManager.get(PermissionActivity.this).getAccounts(); for (Account account : accounts) { if (emailPattern.matcher(account.name).matches()) { possibleEmail = account.name; Log.e("keshav","possibleEmail"+possibleEmail); } Log.e("keshav","possibleEmail gjhh->"+possibleEmail); } } }); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.