get Person Photo from Contact - Android Account

Android examples for Account:Contact Get

Description

get Person Photo from Contact

Demo Code

/*/*from   w ww.ja v  a 2 s .c  o  m*/
    This file is part of dgAlert Classic.

    dgAlert Classic is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    dgAlert Classic is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with dgAlert Classic.  If not, see <http://www.gnu.org/licenses/>.
 */
//package com.java2s;

import android.content.Context;

import android.database.Cursor;

import android.net.Uri;

import android.provider.Contacts;

import android.provider.Contacts.PhotosColumns;

public class Main {
    public static byte[] getPersonPhoto(Context context, String id) {
        if (id == null)
            return null;
        byte photo[] = null;

        Cursor cursor = context.getContentResolver().query(
                Uri.withAppendedPath(Contacts.Photos.CONTENT_URI, id),
                new String[] { PhotosColumns.DATA }, null, null, null);
        if (cursor != null) {
            try {
                if (cursor.getCount() > 0) {
                    cursor.moveToFirst();
                    photo = cursor.getBlob(0);
                    if (photo != null) {
                        return photo;
                        // Log.v("Found photo for person: " + id);
                        // bitmap = BitmapFactory.decodeStream(new
                        // ByteArrayInputStream(photo));
                    }
                }
            } finally {
                cursor.close();
            }
        }
        return photo;
    }
}

Related Tutorials