{"id":10,"date":"2011-03-19T08:29:49","date_gmt":"2011-03-19T00:29:49","guid":{"rendered":"http:\/\/guoh.ai\/lifelog\/?p=10"},"modified":"2011-03-22T21:57:05","modified_gmt":"2011-03-22T13:57:05","slug":"is-android-contacts-avatar-bug-or-not","status":"publish","type":"post","link":"https:\/\/guoh.ai\/lifelog\/2011\/03\/is-android-contacts-avatar-bug-or-not\/","title":{"rendered":"\u8fd9\u662fAndroid\u8054\u7cfb\u4eba\u5934\u50cf\u7684bug\u5417"},"content":{"rendered":"<p>\u7ecf\u8fc7BASE64\u7f16\u7801\u4e4b\u540e\u7684\u56fe\u7247\u5b57\u7b26\u4e32\uff08<a href=\"http:\/\/hb.good.gd\/?FileId=1062387\">\u70b9\u6b64\u4e0b\u8f7d<\/a>\uff0c\u6d4b\u8bd5\u6e90\u7801\u5f53\u4e2d\u4e5f\u6709\uff09\uff0c\u5728Java SE\u73af\u5883\u4e0b\u53ef\u4ee5\u89e3\u7801\u51fa\u6765\u751f\u6210\u4e00\u5f20\u56fe\u7247\uff0c\u4f46\u662f\u901a\u8fc7\u4ee3\u7801\u63d2\u5165\u5230Android\u8054\u7cfb\u4eba\u5934\u50cf\u5c31\u65e0\u6cd5\u663e\u793a\u51fa\u6765\uff08\u663e\u793a\u7684\u4e00\u5f20\u767d\u8272\u56fe\u7247\uff0c\u975eAndroid Contacts\u539f\u751f\u7684\u5360\u4f4d\u7b26\u5934\u50cf\uff09\uff0c\u7528SQLITE MAN\u67e5\u770b\u63d2\u5165\u56fe\u50cf\u540e\u7684\u6570\u636e\u5e93BLOB\u5b57\u6bb5\uff0c\u663e\u793a\u201cFile content cannot be displayed\u201d<br \/>\n\u76ee\u524d\u8fd8\u6ca1\u6709\u89e3\u51b3\u529e\u6cd5\uff0c\u6d4b\u8bd5\u4e86\u5f88\u591a\u56fe\u7247\uff0c\u6709\u7684\u56fe\u7247\u6709\u65f6\u5019\u80fd\u663e\u793a\uff0c\u6709\u65f6\u5019\u4e0d\u80fd\u663e\u793a\uff0c\u8fd9\u662fAndroid\u7684bug\u5417\uff1f<\/p>\n<p>\u63d2\u5165\u56fe\u7247\u7684\u6e90\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\tprivate void doInsert(String imageStr) {\r\n\t\tArrayList&lt;ContentProviderOperation&gt; ops = new ArrayList&lt;ContentProviderOperation&gt;();\r\n\t\tint rawContactInsertIndex = ops.size();\r\n\r\n\t\tops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)\r\n\t\t\t\t.withValue(RawContacts.ACCOUNT_TYPE, null).withValue(\r\n\t\t\t\t\t\tRawContacts.ACCOUNT_NAME, null).withValue(\r\n\t\t\t\t\t\tRawContacts.AGGREGATION_MODE,\r\n\t\t\t\t\t\tRawContacts.AGGREGATION_MODE_DISABLED).build());\r\n\r\n\t\tContentProviderOperation photoOp = ContentProviderOperation.newInsert(\r\n\t\t\t\tData.CONTENT_URI).withValueBackReference(Data.RAW_CONTACT_ID,\r\n\t\t\t\trawContactInsertIndex).withValues(\r\n\t\t\t\tgetPhotoCV(B64.decode(imageStr))).build();\r\n\t\tops.add(photoOp);\r\n\r\n\t\ttry {\r\n\t\t\tgetApplicationContext().getContentResolver().applyBatch(\r\n\t\t\t\t\tContactsContract.AUTHORITY, ops);\r\n\t\t} catch (RemoteException e) {\r\n\t\t\te.printStackTrace();\r\n\t\t} catch (OperationApplicationException e) {\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\t}\r\n\r\n\tprivate ContentValues getPhotoCV(byte&#x5B;] photo) {\r\n\t\tContentValues cv = new ContentValues();\r\n\t\tcv.put(Data.MIMETYPE, Photo.CONTENT_ITEM_TYPE);\r\n\t\tcv.put(Photo.PHOTO, photo);\r\n\t\treturn cv;\r\n\t}<\/pre>\n<p>\u5b8c\u6574\u6d4b\u8bd5\u6e90\u7801\u4e0b\u8f7d<a href=\"http:\/\/hb.good.gd\/?FileId=1062335\">http:\/\/hb.good.gd\/?FileId=1062335<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7ecf\u8fc7BASE64\u7f16\u7801\u4e4b\u540e\u7684\u56fe\u7247\u5b57\u7b26\u4e32\uff08\u70b9\u6b64\u4e0b\u8f7d\uff0c\u6d4b\u8bd5\u6e90\u7801\u5f53\u4e2d\u4e5f\u6709\uff09\uff0c\u5728Java SE\u73af\u5883\u4e0b\u53ef\u4ee5\u89e3\u7801\u51fa\u6765\u751f\u6210\u4e00\u5f20\u56fe\u7247\uff0c\u4f46\u662f\u901a\u8fc7\u4ee3\u7801\u63d2\u5165\u5230Android\u8054\u7cfb\u4eba\u5934\u50cf\u5c31\u65e0\u6cd5\u663e\u793a\u51fa\u6765\uff08\u663e\u793a\u7684\u4e00\u5f20\u767d\u8272\u56fe\u7247\uff0c\u975eAndroid Contacts\u539f\u751f\u7684\u5360\u4f4d\u7b26\u5934\u50cf\uff09\uff0c\u7528SQLITE MAN\u67e5\u770b\u63d2\u5165\u56fe\u50cf\u540e\u7684\u6570\u636e\u5e93BLOB\u5b57\u6bb5\uff0c\u663e\u793a\u201cFile content cannot be displayed\u201d \u76ee\u524d\u8fd8\u6ca1\u6709\u89e3\u51b3\u529e\u6cd5\uff0c\u6d4b\u8bd5\u4e86\u5f88\u591a\u56fe\u7247\uff0c\u6709\u7684\u56fe\u7247\u6709\u65f6\u5019\u80fd\u663e\u793a\uff0c\u6709\u65f6\u5019\u4e0d\u80fd\u663e\u793a\uff0c\u8fd9\u662fAndroid\u7684bug\u5417\uff1f \u63d2\u5165\u56fe\u7247\u7684\u6e90\u7801\u5982\u4e0b\uff1a private void doInsert(String imageStr) { ArrayList&lt;ContentProviderOperation&gt; ops = new ArrayList&lt;ContentProviderOperation&gt;(); int rawContactInsertIndex = ops.size(); ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI) .withValue(RawContacts.ACCOUNT_TYPE, null).withValue( RawContacts.ACCOUNT_NAME, null).withValue( RawContacts.AGGREGATION_MODE, RawContacts.AGGREGATION_MODE_DISABLED).build()); ContentProviderOperation photoOp = ContentProviderOperation.newInsert( Data.CONTENT_URI).withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex).withValues( getPhotoCV(B64.decode(imageStr))).build(); ops.add(photoOp); try { getApplicationContext().getContentResolver().applyBatch( ContactsContract.AUTHORITY, ops); } catch (RemoteException e) { e.printStackTrace(); } catch (OperationApplicationException e) { &hellip; <a href=\"https:\/\/guoh.ai\/lifelog\/2011\/03\/is-android-contacts-avatar-bug-or-not\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">\u8fd9\u662fAndroid\u8054\u7cfb\u4eba\u5934\u50cf\u7684bug\u5417<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-10","post","type-post","status-publish","format-standard","hentry","category-android"],"_links":{"self":[{"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/posts\/10","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/comments?post=10"}],"version-history":[{"count":8,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/posts\/10\/revisions"}],"predecessor-version":[{"id":12,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/posts\/10\/revisions\/12"}],"wp:attachment":[{"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/media?parent=10"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/categories?post=10"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/tags?post=10"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}