如何让姓Android手机拥有者和姓? [英] how to get firstname and lastname of Android phone owner?
问题描述
有没有办法让Android手机主人的名字和姓氏?我已经在互联网上搜索,但我有没有运气。我偶然发现了<一href="http://stackoverflow.com/questions/4301064/how-to-get-the-firstname-and-lastname-from-android-contacts">this在Stackoverlow的问题,但这种越来越名字的所有联系人和姓氏。我需要的是刚刚拿到主人的名字和姓氏。
Is there a way to get the firstname and lastname of Android phone owner? I've search the internet but I have no luck. I stumbled upon this question in Stackoverlow but this is getting firstname and lastname of all contacts. What I need is just to get the owner's firstname and lastname.
推荐答案
我觉得这是可以ICS起只 - 看看本作的详细信息<一个href="http://android-$c$clabs.appspot.com/resources/tutorials/contactsprovider/ex1.html">http://android-$c$clabs.appspot.com/resources/tutorials/contactsprovider/ex1.html
I think this is available ICS onwards only - Look at this for more info 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包括一个个人配置文件,重新presents设备所有者 - 此配置文件被称为我的资料,并存储在 ContactsContract.Profile
表。只要你可以阅读从用户的配置文件数据,你
Android includes a personal profile that represents the device owner - this profile is known as the "Me" profile and is stored in the ContactsContract.Profile
table. You can read data from the user's profile so long as you
添加READ_PROFILE和READ_CONTACTS允许你的AndroidManifest.xml。
最相关的领域你是从联系DISPLAY_NAME列,可能是StructuredName领域
The most relevant fields for you are the DISPLAY_NAME column from the Contact and possibly the StructuredName fields
这篇关于如何让姓Android手机拥有者和姓?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!