get Contact Photo Bitmap - Android Account

Android examples for Account:Contact Get

Description

get Contact Photo Bitmap

Demo Code


//package com.java2s;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.IOException;

import android.content.Context;
import android.content.res.AssetFileDescriptor;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;

public class Main {
    public static Bitmap getContactPhotoBitmap(Context context, String uri) {
        AssetFileDescriptor afd = null;// w w w  . j av  a2  s.c  o m
        try {
            afd = context.getContentResolver().openAssetFileDescriptor(
                    Uri.parse(uri), "r");
            FileDescriptor fileDescriptor = afd.getFileDescriptor();

            if (fileDescriptor != null) {
                return BitmapFactory.decodeFileDescriptor(fileDescriptor,
                        null, null);
            }
        } catch (FileNotFoundException e) {
        } finally {
            if (afd != null) {
                try {
                    afd.close();
                } catch (IOException e) {
                }
            }
        }
        return null;
    }
}

Related Tutorials