Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question