How to get android phone user's google account name?

后端 未结 2 985
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-25 04:00

So I am making mobile game with unity engine, think to release to android target.

Now my game will have my own custom highscore board, there I think when user earn score

相关标签:
2条回答
  • 2021-01-25 04:16

    try this

    AccountManager manager = AccountManager.get(context);
    Account[] accounts = manager.getAccountsByType("com.google");
    List<String> username = new LinkedList<String>();
    
    for (Account account : accounts) {
        username.add(account.name);
    }
    

    and add permission to android manifest

    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    
    0 讨论(0)
  • 2021-01-25 04:33

    If you have a string asdf@gmail.com and you want everything before the @ you can use .split();

    String email = asdf@gmail.com
    String[] parts = email.split("@");
    String nickname = parts[0];
    
    0 讨论(0)
提交回复
热议问题