【发布时间】:2014-07-24 19:55:38
【问题描述】:
我正在创建一个应用程序,我有一张用户照片,我想自动提取它。我真的不知道该怎么做,或者什么是最好的方法。
有没有办法拉取google账号照片?考虑到全世界很多人可能根本没有 Google 帐户,这甚至可能不是最好的方法。
ContactProvider 中是否有电话用户的默认联系人,如果有,我将如何获取它以及它拥有的照片。抱歉,我没有任何代码,只是不知道从哪里开始,建议或链接可能会为我指明正确的方向。
我试过的好的代码
String[] mProjection = new String[]
{
Profile._ID,
Profile.DISPLAY_NAME_PRIMARY,
Profile.LOOKUP_KEY,
Profile.PHOTO_THUMBNAIL_URI
};
// Retrieves the profile from the Contacts Provider
Cursor mProfileCursor = mContext.getContentResolver().query(
Profile.CONTENT_URI,
mProjection ,
null,
null,
null);
try {
if (mProfileCursor.moveToFirst()) {
byte[] data = mProfileCursor.getBlob(0); //error on this line
if (data != null) {
InputStream is = new ByteArrayInputStream(data);
imageBit = BitmapFactory.decodeStream(is);
}
}
} finally {
mProfileCursor.close();
}
我一直在指出的行上收到错误:
android.database.sqlite.SQLiteException:未知错误(代码 0):nativeGetBlob 中的 INTEGER 数据
编辑 2:所以我将 0 更改为 3 以获取个人资料照片,它修复了我的一个错误,但现在我从解码流中获得的 imageBit 为空。但是字节 [] 不是,所以我不知道将字节 [] 转换为位图的问题是什么
【问题讨论】:
-
0 将是 _ID,尝试 3。并且很确定它不会返回 blob,而是返回 URI,因此您可以将 MediaStore.Images.Media.getBitmap 与内容解析器和此 uri 一起使用。跨度>
-
是的,这似乎正在取得进展,它修复了我的一个错误,但现在我从解码流中得到的 imageBit 为空。 byte[] 但是不是,所以我不知道将 byte[] 转换为位图的问题是什么
标签: android contacts google-account