Android Contact Get getEmail(int contactId)

Here you can find the source of getEmail(int contactId)

Description

This method used to get mail id from contact id.

Parameter

Parameter Description
contactId represented contact id

Return

represented

Declaration

@SuppressWarnings("deprecation")
private static String getEmail(int contactId) 

Method Source Code

//package com.java2s;

import android.app.Activity;

import android.database.Cursor;

import android.provider.ContactsContract.CommonDataKinds.Email;

import android.provider.ContactsContract.Data;

public class Main {
    public static Activity mSmartAndroidActivity;

    /**//from  ww w.  ja va 2 s . c o m
     * This method used to get mail id from contact id.
     * 
     * @param contactId
     *            represented contact id
     * @return represented {@link String}
     */
    @SuppressWarnings("deprecation")
    private static String getEmail(int contactId) {
        String emailStr = "";
        final String[] projection = new String[] { Email.DATA, // use
                // Email.ADDRESS
                // for API-Level
                // 11+
                Email.TYPE };

        final Cursor email = mSmartAndroidActivity.managedQuery(
                Email.CONTENT_URI, projection, Data.CONTACT_ID + "=?",
                new String[] { String.valueOf(contactId) }, null);

        if (email.moveToFirst()) {
            final int contactEmailColumnIndex = email
                    .getColumnIndex(Email.DATA);

            while (!email.isAfterLast()) {
                emailStr = emailStr
                        + email.getString(contactEmailColumnIndex) + ";";
                email.moveToNext();
            }
        }
        email.close();
        return emailStr;

    }
}

Related

  1. getOperatorByNumber( ContentResolver contentResolver, String number)