I am trying to show contact pictures in my application but I am getting pictures of those who were added manually only and not those which are synced with facebook. How to work around this? Here is my code below:
Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(PhotoId));
InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(context.getContentResolver(), uri);
return BitmapFactory.decodeStream(input);
It doesn't work for contacts that are synced from FB only. You'll need to use the FB graph API and fetch the photo from there; and you need to know the contacts facebook name.
Bitmap contactPhoto = getImageBitmap("http://graph.facebook.com/mathiaslin/picture?type=square");
final private static Bitmap getImageBitmap(String url) {
Bitmap bm = null;
try {
URLConnection conn = new URL(url).openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
} catch (IOException e) {
Log.e(TAG, "Error getting bitmap", e);
}
return bm;
}
I have tried every solution found on Stack Overflow at the time of writing this and nothing will correctly retrieve a photo that came from Facebook through the official Facebook app account sync adapter.
To be clear, people posting solutions who "think" they work are probably using HTC sense phones that come with a Facebook sync adapter written by HTC that doesn't have the same security requirements as the official Facebook app.
It's a security thing and one of the methods did manage to try to access the bytes of the facebook photo and you will end up with an SqliteException saying that the content requested is restricted.
Same code run as a system process will pull the photo fine. It is just not possible as of right now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With