Getting the Gmail Id of the User In Android 6.0 marshmallow

后端 未结 3 794
遇见更好的自我
遇见更好的自我 2021-01-15 05:50

I am getting email id by using android.permission.GET_ACCOUNTS permission.

 try {
            Account[] accounts = AccountManager.get(this).getA         


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-15 06:23

    This code is working, Tested on Android 4.4.4, 5.0.1, 6.0 and 6.0.1

    String possibleEmail = "";
        final Account[] accounts = AccountManager.get(context).getAccounts();
        //Log.e("accounts","->"+accounts.length);
        for (Account account : accounts) {
            if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) {
                possibleEmail = account.name;
            }
        }
    

    possibleEmail is the email of the device.

提交回复
热议问题