¿Cómo se puede obtener la dirección de correo electrónico de un usuario de Android?

Tengo android.permission.READ_OWNER_DATA pero no puedo encontrar ningún código confiable que explique cómo puedo leer la dirección de correo electrónico del propietario del dispositivo. ¿Cómo puedo hacer esto?

¿Por qué quieres hacer eso?

 import android.accounts.Account; import android.accounts.AccountManager; import android.content.Context; /** * This class uses the AccountManager to get the primary email address of the * current user. */ 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; } } 

En su AnroidManifest.xml

  

Trabajando en la versión de MarshMallow

btn_click = (Botón) findViewById (R.id.btn_click);

 btn_click.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { 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 Marshmallow 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 { 

// Inferior a Marshmallow

  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); } } });