Get gmail profile image and full name

后端 未结 2 1635
故里飘歌
故里飘歌 2021-01-14 14:39

I am preparing a login page for my app. I wanted to do the same thing that twitter is doing. They are helping the user and predefining some fields like email, name and prof

2条回答
  •  滥情空心
    2021-01-14 15:18

    Get Account Full Name

    First Add this permission into AndroidManifest.xml file

     
    

    Java Code

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

    Call getAccount();

        Account account = getAccount(AccountManager.get(context));
        String accountName = account.name;
        String fullName = accountName.substring(0,accountName.lastIndexOf("@"));
        emailEditText.setText(accountName);
        fullNameEditText.setText(fullName);
    

    If Account Email is -

    abc@gmail.com

    then Name is -

    abc

提交回复
热议问题