【发布时间】:2015-11-15 03:47:27
【问题描述】:
我知道如何从ContentResolver 检索用户配置文件。如果我有位图,如何将其设置为用户头像(如果不存在则替换或设置)?
我加载用户配置文件如下:
Uri dataUri = Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI, ContactsContract.Contacts.Data.CONTENT_DIRECTORY);
String[] selection = new String[]
{
ContactsContract.Profile._ID,
ContactsContract.Profile.DISPLAY_NAME,
ContactsContract.Profile.PHOTO_URI,
ContactsContract.Profile.LOOKUP_KEY
};
Cursor cursor = MainApp.get().getContentResolver().query(
dataUri,
selection,
null,
null,
null);
if (cursor != null)
{
int id = cursor.getColumnIndex(ContactsContract.Profile._ID);
int name = cursor.getColumnIndex(ContactsContract.Profile.DISPLAY_NAME);
int photoUri = cursor.getColumnIndex(ContactsContract.Profile.PHOTO_URI);
int lookupKey = cursor.getColumnIndex(ContactsContract.Profile.LOOKUP_KEY);
try
{
if (cursor.moveToFirst())
{
int phId = cursor.getInt(id);
mName = cursor.getString(name);
mImageUri = cursor.getString(photoUri);
mLookupKey = cursor.getString(lookupKey);
mExists = true;
}
}
finally
{
cursor.close();
}
}
【问题讨论】:
-
也许这会有所帮助? stackoverflow.com/questions/17789256/…
-
谢谢。实际上,使用联系人和用户个人资料执行此操作有些不同...但我刚刚弄清楚它是如何工作的
-
您想为您的联系人添加位图吗?
-
我的个人资料,不是联系人...但正如我所说,我现在知道该怎么做...
-
@prom85 如果您想通了,请考虑使用解决方案发布您的问题的答案