Android: How to load chunked image?
-
How to load image for Google Contact from Google Contacts API.
-
Answer:
According to Google's official documentation (https://developers.google.com/google-apps/contacts/v3/#retrieving_a_contacts_photo), this is how you retrieve contact image using the Contacts API: Retrieving a contact's photo To retrieve a contact's photo, send an authorized GET request to the contact's photo link URL. The URL is of the form: https://www.google.com/m8/feeds/photos/media/%7BuserEmail%7D/%7BcontactId%7D With the appropriate values in place of userEmail and contactID. Note: The special userEmail value default can be used to refer to the authenticated user. The photo link can be retrieved from the contact entry returned by the API: <entry xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='<var>contactEtag</var>'> <id> http://www.google.com/m8/feeds/contacts/<var>userEmail</var>/base/<var>contactId</var> </id> ... <title>Full Name</title> <gd:name> <gd:fullName>Full Name</gd:fullName> </gd:name> <link rel='http://schemas.google.com/contacts/2008/rel#photo' type='image/*' href='https://www.google.com/m8/feeds/photos/media/<var>userEmail</var>/<var>contactId</var>' gd:etag='<var>photoEtag</var>'/> <link rel='self' type='application/atom+xml' href='https://www.google.com/m8/feeds/contacts/<var>userEmail</var>/full/<var>contactId</var>'/> ... </entry> Note: If a contact does not have a photo, then the photo link element has no gd:etag attribute. Upon success, the server responds with an HTTP 200 OK status code and the photo data bytes. I went through other websites too and came across this blog(http://thinkandroid.wordpress.com/2009/12/30/handling-contact-photos-all-api-levels/). It explains how to handle contact photos for API levels 5/6 (a little outdated?). I am showing the code written there below: Loading Contact Photos: For API LEVEL 5 / 6 the code looks like: public static Bitmap loadContactPhoto(ContentResolver cr, long id) { Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id); InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(cr, uri); if (input == null) { return getBitmapFromURL("http://thinkandroid.wordpress.com"); } return BitmapFactory.decodeStream(input); } Now, for setting photos, things get slightly more complicated: For API LEVEL 5 / 6 the code looks like: public static void setContactPhoto(ContentResolver c, byte[] bytes, long personId) { ContentValues values = new ContentValues(); int photoRow = -1; String where = ContactsContract.Data.RAW_CONTACT_ID + " = " + personId + " AND " + ContactsContract.Data.MIMETYPE + "=='" + ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'"; Cursor cursor = c.query(ContactsContract.Data.CONTENT_URI, null, where, null, null); int idIdx = cursor.getColumnIndexOrThrow(ContactsContract.Data._ID); if (cursor.moveToFirst()) { photoRow = cursor.getInt(idIdx); } cursor.close(); values.put(ContactsContract.Data.RAW_CONTACT_ID, personId); values.put(ContactsContract.Data.IS_SUPER_PRIMARY, 1); values.put(ContactsContract.CommonDataKinds.Photo.PHOTO, bytes); values.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE); if (photoRow >= 0) { c.update(ContactsContract.Data.CONTENT_URI, values, ContactsContract.Data._ID + " = " + photoRow, null); } else { c.insert(ContactsContract.Data.CONTENT_URI, values); } } Disclaimer: I have never used the Google Contacts API before, neither have I tested the code given in these websites. So, I cannot guarantee the working of the code above. But this should help you get started on your problem.
Kangkan Boro at Quora Visit the source
Related Q & A:
- How To Load Rss Into Php?Best solution by Stack Overflow
- How To Load An Activity In A fragment?Best solution by Stack Overflow
- How to change thin image to fat image in iPhone SDK?Best solution by Stack Overflow
- How to upload the image to a server in Android PhoneGap?Best solution by Stack Overflow
- How to load an image to an applet?Best solution by stackoverflow.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.