How do you get the Android\'s primary e-mail address (or a list of e-mail addresses)?
It\'s my understanding that on OS 2.0+ there\'s support for multiple e-mail add
Working In MarshMallow Operating System
btn_click=(Button) 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 {
// Lower then 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);
}
}
});