R
R
rafaelSalihov2020-06-08 06:10:38
Android
rafaelSalihov, 2020-06-08 06:10:38

How to get google account name?

Created a method
when clicking on the text textView1 in the log with the Account tag, the number of accounts is displayed 0. Although I definitely have 1 account, why is that?
And it crashes with an error, it can’t substitute the name of the account in the text

, permission is also there

<uses-permission android:name="android.permission.GET_ACCOUNTS" />

public void onClick(View v){
  AccountManager am = AccountManager.get(this); // current Context
  //AccountManager am = (AccountManager) getSystemService(ACCOUNT_SERVICE); // видел такой способ
   
  Account[] accounts = am.getAccountsByType("com.google");
  Log.i("Account", accounts.length + "");
  TextView tvInfo = (TextView)findViewById(R.id.textView1);
  tvInfo.setText(accounts[0].name);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2020-06-08
@402d

starting with android 6, the line in the manifest is not enough to get permissions.
https://startandroid.ru/en/blog/508-android-permis...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question