AccountManager
を使います。(API Level 5)
AndroidManifest.xml に
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
を書くのを忘れずに。
AccountManager.get(this) で現在の Context と関連付いている
AccountManager のインスタンスが取得できます。
このインスタンスに対して、getAccounts() や
getAccountsByType() で Account の配列が取得できます。
Account クラスはアカウント名とタイプを保持しています。
アカウント名や名前を取得するには、こんなかんじ。
- private String[] getAccounts() {
- ArrayList<string> accountsInfo = new ArrayList<string>();
- Account[] accounts = AccountManager.get(this).getAccounts();
- for (Account account : accounts) {
- String name = account.name;
- String type = account.type;
- int describeContents = account.describeContents();
- int hashCode = account.hashCode();
- accountsInfo.add("name = " + name +
- "\ntype = " + type +
- "\ndescribeContents = " + describeContents +
- "\nhashCode = " + hashCode);
- }
- String[] result = new String[accountsInfo.size()];
- accountsInfo.toArray(result);
- return result;
- }
- </string></string>

0 件のコメント:
コメントを投稿