fetch Contact Photo from Contacts - Android Account

Android examples for Account:Contact

Description

fetch Contact Photo from Contacts

Demo Code


//package com.java2s;
import android.content.ContentUris;
import android.content.Context;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.provider.ContactsContract.Contacts;

import java.io.InputStream;

public class Main {
    public static Bitmap fetchContactPhoto(Context context, long id) {
        Uri uri = ContentUris.withAppendedId(Contacts.CONTENT_URI, id);
        InputStream input = Contacts.openContactPhotoInputStream(
                context.getContentResolver(), uri);

        return input == null ? null : BitmapFactory.decodeStream(input);
    }//  w  ww  .  j  av a  2 s  . c  om
}

Related Tutorials