java - Get User's Google Account Profile Picture -
i have far looked @ many questions topic, not single answer has worked me far. in code user's google account , contact info. can @ email , display name fine. when grab id number , use how http://developer.android.com/reference/android/provider/contactscontract.contacts.photo.html have me use it, inputstream comes null. when debug through following method program never loads blob data, skips down finally.
public inputstream openphoto(long contactid) { uri contacturi = contenturis.withappendedid(contactscontract.contacts.content_uri, contactid); uri photouri = uri.withappendedpath(contacturi, contactscontract.contacts.photo.content_directory); cursor cursor = context.getcontentresolver().query(photouri, new string[] {contactscontract.contacts.photo.photo}, null, null, null); if (cursor == null) { return null; } try { if (cursor.movetofirst()) { byte[] data = cursor.getblob(0); if (data != null) { return new bytearrayinputstream(data); } } } { cursor.close(); } return null; }
does mean selected contact not have profile image??? no not case accessing personal gmail account , giving me other data correctly. id following code (along email , display name). email googleaccount.name
accountmanager accountmanager; accountmanager = accountmanager.get(context); account[] account = accountmanager.getaccounts(); account googleaccount = null; for(int = 0; < account.length; i++) { if(account[i].type.equals("com.google")) { googleaccount = account[i]; } } cursor c = context.getcontentresolver().query(contactscontract.profile.content_uri, null, null, null, null); int count = c.getcount(); c.movetofirst(); string id = ""; string displayname = ""; string[] columnnames = c.getcolumnnames(); int position = c.getposition(); if (count == 1 && position == 0) { (int j = 0; j < columnnames.length; j++) { string columnname = columnnames[j]; string columnvalue = c.getstring(c.getcolumnindex(columnname)); if(columnname.equals("_id")) id = columnvalue; if(columnname.equals("display_name")) displayname = columnvalue; // consume values here } } c.close();
why inputstream coming null? got code directly google. has had problem code before?
Comments
Post a Comment