Here you can find the source of getPhoneNumber(int contactId)
Parameter | Description |
---|---|
contactId | represented contact id |
@SuppressWarnings("deprecation") private static String getPhoneNumber(int contactId)
//package com.java2s; import android.app.Activity; import android.database.Cursor; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.Data; public class Main { public static Activity mSmartAndroidActivity; /**// www . j a v a2 s. c o m * This method used to get phone number from contact id. * * @param contactId * represented contact id * @return represented {@link String} */ @SuppressWarnings("deprecation") private static String getPhoneNumber(int contactId) { String phoneNumber = ""; final String[] projection = new String[] { Phone.NUMBER, Phone.TYPE, }; final Cursor phone = mSmartAndroidActivity.managedQuery( Phone.CONTENT_URI, projection, Data.CONTACT_ID + "=?", new String[] { String.valueOf(contactId) }, null); if (phone.moveToFirst()) { final int contactNumberColumnIndex = phone .getColumnIndex(Phone.DATA); while (!phone.isAfterLast()) { phoneNumber = phoneNumber + phone.getString(contactNumberColumnIndex) + ";"; phone.moveToNext(); } } phone.close(); return phoneNumber; } }