如何从 "Me" 个人资料 Android 中获取所有者的联系信息
How to get Owner's Contact Info from "Me" Profile Android
我成功获得了 Display/Full 所有者姓名。但是我想得到所有者的 phone 号码和头像。我的意思是,当我们转到联系人时,有一个名为 "ME" 的个人资料,我想获取这些信息。我怎么能够?最好用代码进行简要说明。 (谢谢)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = (TextView) findViewById(R.id.txtv_contact_name);
number = (TextView) findViewById(R.id.txtv_contact_number);
imageView = (ImageView) findViewById(R.id.img_contact);
Cursor c = getApplication().getContentResolver().query(ContactsContract.Profile.CONTENT_URI, null, null, null, null);
if (c.moveToFirst()) {
name.setText(c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));
}
c.close();
}
构造ProfileUri
有一个特殊的方法,试试这个:
// profile uri
Uri uri = Uri.withAppendedPath(Profile.CONTENT_URI, Contacts.Data.CONTENT_DIRECTORY);
// cursor with all the data on that uri
Cursor cur = getContentResolver().query(uri, null, null, null, null);
// dump the cursor
DatabaseUtils.dumpCursor(cur);
cur.close();
我成功获得了 Display/Full 所有者姓名。但是我想得到所有者的 phone 号码和头像。我的意思是,当我们转到联系人时,有一个名为 "ME" 的个人资料,我想获取这些信息。我怎么能够?最好用代码进行简要说明。 (谢谢)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = (TextView) findViewById(R.id.txtv_contact_name);
number = (TextView) findViewById(R.id.txtv_contact_number);
imageView = (ImageView) findViewById(R.id.img_contact);
Cursor c = getApplication().getContentResolver().query(ContactsContract.Profile.CONTENT_URI, null, null, null, null);
if (c.moveToFirst()) {
name.setText(c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));
}
c.close();
}
构造ProfileUri
有一个特殊的方法,试试这个:
// profile uri
Uri uri = Uri.withAppendedPath(Profile.CONTENT_URI, Contacts.Data.CONTENT_DIRECTORY);
// cursor with all the data on that uri
Cursor cur = getContentResolver().query(uri, null, null, null, null);
// dump the cursor
DatabaseUtils.dumpCursor(cur);
cur.close();