Android Address Get getAddress(int contactId)

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

Description

This method used to get address from contact id.

Parameter

Parameter Description
contactId represented contact id

Return

represented

Declaration

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

Method Source Code

//package com.java2s;

import android.app.Activity;

import android.database.Cursor;

import android.provider.ContactsContract;

public class Main {
    public static Activity mSmartAndroidActivity;

    /**/*from ww  w .j a va2  s.c  o  m*/
     * This method used to get address from contact id.
     * 
     * @param contactId
     *            represented contact id
     * @return represented {@link String}
     */
    @SuppressWarnings("deprecation")
    private static String getAddress(int contactId) {
        String postalData = "";
        String addrWhere = ContactsContract.Data.CONTACT_ID + " = ? AND "
                + ContactsContract.Data.MIMETYPE + " = ?";
        String[] addrWhereParams = new String[] {
                String.valueOf(contactId),
                ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE };

        Cursor addrCur = mSmartAndroidActivity.managedQuery(
                ContactsContract.Data.CONTENT_URI, null, addrWhere,
                addrWhereParams, null);

        if (addrCur.moveToFirst()) {
            postalData = addrCur
                    .getString(addrCur
                            .getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS));
        }
        addrCur.close();
        return postalData;
    }
}

Related

  1. isVictoriaAddress(Address address)
  2. getLatLongFromAddress(String address)