final Spinner emailsList = (Spinner) findViewById(R.id.email_list);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_dropdown_item_1line, getUserEmails());
emailsList.setAdapter(adapter);
public ArrayList<String> getUserEmails() {
AccountManager manager = AccountManager.get(this);
Account[] accounts = manager.getAccountsByType("com.google");
ArrayList<String> possibleEmails = new ArrayList<>();
for (Account account : accounts) {
possibleEmails.add(account.name);
}
return possibleEmails;
}
清单
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
XML
<Spinner
android:id="@+id/email_list"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:background="@drawable/loginfields_borders"
android:padding="12dp"
android:hint="List of emails"
android:textColor="#a3a3a3"
android:textSize="11dp" />
请帮助为什么它没有在微调器中显示电子邮件,因为它没有显示错误,只是显示如下警告
03-16 11:15:58.910 16209-16209/com.example.aiousecurityapplication I/HwPointEventFilter: do not support AFT because of no config