【发布时间】:2012-10-16 14:17:51
【问题描述】:
有没有办法获取 Android 手机所有者的名字和姓氏?我已经搜索了互联网,但我没有运气。我在 Stackoverlow 中偶然发现了this 问题,但这是获取所有联系人的名字和姓氏。我需要的只是获取所有者的名字和姓氏。
【问题讨论】:
有没有办法获取 Android 手机所有者的名字和姓氏?我已经搜索了互联网,但我没有运气。我在 Stackoverlow 中偶然发现了this 问题,但这是获取所有联系人的名字和姓氏。我需要的只是获取所有者的名字和姓氏。
【问题讨论】:
我认为这仅适用于 ICS - 查看此以获取更多信息 http://android-codelabs.appspot.com/resources/tutorials/contactsprovider/ex1.html
Cursor c = activity.getContentResolver().query(ContactsContract.Profile.CONTENT_URI, null, null, null, null);
int count = c.getCount();
String[] columnNames = c.getColumnNames();
boolean b = c.moveToFirst();
int position = c.getPosition();
if (count == 1 && position == 0) {
for (int j = 0; j < columnNames.length; j++) {
String columnName = columnNames[j];
String columnValue = c.getString(c.getColumnIndex(columnName)));
...
//Use the values
}
}
c.close();
Android 包含一个代表设备所有者的个人配置文件 - 此配置文件称为“我”配置文件,存储在 ContactsContract.Profile 表中。您可以从用户的个人资料中读取数据,只要您
在您的 AndroidManifest.xml 中添加 READ_PROFILE 和 READ_CONTACTS 权限。
与您最相关的字段是联系人中的 DISPLAY_NAME 列,可能还有 StructuredName 字段
【讨论】:
试试这个:
final AccountManager manager = AccountManager.get(this);
final Account[] accounts = manager.getAccountsByType("com.google");
final int size = accounts.length;
String[] names = new String[size];
for (int i = 0; i < size; i++) {
names[i] = accounts[i].name;
}
【讨论】: