Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import android.net.Uri;

import android.provider.ContactsContract;

import java.io.IOException;
import java.io.InputStream;

public class Main {
    /**
     * Get the contact photo from a contact URI.
     *
     * @param context The context.
     * @param contactUri The contact URI.
     *
     * @return The contact photo.
     */
    public static Bitmap getContactPhoto(final Context context, Uri contactUri) {
        Bitmap bitmap = null;
        if (contactUri != null) {
            InputStream inputStream = ContactsContract.Contacts
                    .openContactPhotoInputStream(context.getContentResolver(), contactUri);
            if (inputStream != null) {
                bitmap = BitmapFactory.decodeStream(inputStream);
                try {
                    inputStream.close();
                } catch (IOException e) {

                }
            }
        }

        return bitmap;
    }
}