權限進入清單沒有得到主電子郵件ID在Android項目
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
我的XML
<TextView
android:id="@+id/tv_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
MainActivity.java
public class MainActivity extends AppCompatActivity {
private FirebaseAnalytics firebaseAnalytics;
ImageView GoToNewActivity;
ImageView GoToNewActivity1;
TextView tvID;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvID = (TextView) findViewById(R.id.tv_id);
String email = getEmiailID(this);
if(email != null) {
tvID.setText(email);
} else {
tvID.setText("Account haven't been found");
}
private String getEmiailID(Context context) {
AccountManager accountManager = AccountManager.get(context);
Account account = getAccount(accountManager);
if (account == null) {
return null;
} else {
return account.name;
}
}
private 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;
}
}
據印戶口也沒有發現,意味着沒有獲得主要電子郵我在我的Android設備中有我的主要電子郵件。我的代碼錯了嗎?
它給錯誤無法解析符號背景 –
@GauravMehra通過YourActivity.this作爲上下文我的朋友 –
其打印打招呼主音,不打印電子郵件 –