public static Intent getContactPhoneIntent() { Intent intent = new Intent(Intent.ACTION_PICK); /* * intent.setAction(Intent.ACTION_GET_CONTENT); * intent.setType(Contacts.Phones.CONTENT_ITEM_TYPE); */ if (isCompatible(5)) { // Don't use constant to allow backward compat simply intent.setData(Uri.parse("content://com.android.contacts/contacts")); } else { // Fallback for android 4 intent.setData(Contacts.People.CONTENT_URI); } return intent; }
public void create(Contact newPhoneContact) throws Exception { // first, we have to create the contact ContentValues newPhoneValues = new ContentValues(); newPhoneValues.put(Contacts.People.NAME, newPhoneContact.getName()); Uri newPhoneRow = resolver.insert(Contacts.People.CONTENT_URI, newPhoneValues); // then we have to add a number newPhoneValues.clear(); newPhoneValues.put(Contacts.People.Phones.TYPE, Contacts.People.Phones.TYPE_MOBILE); newPhoneValues.put(Contacts.Phones.NUMBER, newPhoneContact.getNumber()); // insert the new phone number in the database using the returned uri from creating the contact newPhoneRow = resolver.insert(Uri.withAppendedPath(newPhoneRow, Contacts.People.Phones.CONTENT_DIRECTORY), newPhoneValues); // if contacts uri returned, there was an error with adding the number if (newPhoneRow.getPath().contains("people")) { throw new Exception(String.valueOf(R.string.error_phone_number_not_stored)); } // if phone uri returned, everything went OK if (!newPhoneRow.getPath().contains("phones")) { // some unknown error has happened throw new Exception(String.valueOf(R.string.error_phone_number_error)); } }
public Uri retrieveContactUri(Contact contact) { String id = contact.getId(); String[] projection = new String[] { Contacts.Phones.PERSON_ID }; String path = null; Cursor result; if (null != id) { Uri uri = ContentUris.withAppendedId(Contacts.Phones.CONTENT_URI, Long.valueOf(id)); result = resolver.query(uri, projection, null, null, null); } else { String selection = "name='?' AND number='?'"; String[] selectionArgs = new String[] { contact.getName(), contact.getNumber() }; result = resolver.query(Contacts.Phones.CONTENT_URI, projection, selection, selectionArgs, null); } if (null != result) { result.moveToNext(); path = result.getString(0); result.close(); } if (null == path) { return null; } return Uri.withAppendedPath(Contacts.People.CONTENT_URI, path); }
@Override public String getAllContactsPhoneNumbers(Activity activity) { StringBuilder sb = new StringBuilder(1024); String[] PROJECTION = new String[] { PhonesColumns.NUMBER }; Cursor c = activity.managedQuery(Contacts.Phones.CONTENT_URI, PROJECTION, null, null, Contacts.Phones.DEFAULT_SORT_ORDER); if (c.moveToFirst()) { sb.append(c.getString(0)); while (c.moveToNext()) { sb.append(","); sb.append(c.getString(0)); } } c.close(); return sb.toString(); }
@Override public String getAllContactsEmailAddresses(Activity activity) { StringBuilder sb = new StringBuilder(1024); String[] PROJECTION = new String[] { Contacts.ContactMethods.DATA }; Cursor c = activity.managedQuery( Contacts.ContactMethods.CONTENT_EMAIL_URI, PROJECTION, null, null, Contacts.ContactMethods.DEFAULT_SORT_ORDER); if (c.moveToFirst()) { sb.append(c.getString(0)); while (c.moveToNext()) { sb.append(","); sb.append(c.getString(0)); } } c.close(); return sb.toString(); }
public String[] getContacts(Context context, boolean withNumbers) { Vector ids = new Vector(); String selection = null; if (withNumbers) { selection = ContactsContract.Contacts.HAS_PHONE_NUMBER + "=1"; } Cursor cursor = context.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, selection, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC"); while (cursor.moveToNext()) { String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)); ids.add(contactId); } cursor.close(); String[] contacts = new String[ids.size()]; for (int i = 0; i < ids.size(); i++) { String id = (String) ids.elementAt(i); contacts[i] = id; } return contacts; }
public String[] getContacts(Activity context, boolean withNumbers) { Vector ids = new Vector(); String selection = null; if (withNumbers) { selection = ContactsContract.Contacts.HAS_PHONE_NUMBER + "=1"; } Cursor cursor = context.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, selection, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC"); while (cursor.moveToNext()) { String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)); ids.add(contactId); } cursor.close(); String[] contacts = new String[ids.size()]; for (int i = 0; i < ids.size(); i++) { String id = (String) ids.elementAt(i); contacts[i] = id; } return contacts; }
public static boolean doesUriContainLocationInfo(Context ctx, Uri uri) throws RuntimeException { //Log.d(TAG, "uri.toString()=="+uri.toString()); final int sdkVersion = Integer.parseInt( Build.VERSION.SDK ); // Build.VERSION.SDK_INT was introduced after API level 3 and so is not compatible with 1.5 devices. if( 5 > sdkVersion ){ // Anrdoid 1.x series code. if(uri.toString().startsWith(android.provider.Contacts.People.CONTENT_URI.toString())){ return LocationUtil.doesContactUriContainLocationInfoSDK3(ctx, uri); }else{ return false; } }else{ // Android 2.x series code. if(uri.toString().startsWith("content://com.android.contacts/contacts/lookup")){ return LocationUtil.doesContactUriContainLocationInfoSDK5(ctx, uri); }else{ return false; } } }
static String[] getLabelsForKind(Context context, int kind) { final Resources resources = context.getResources(); switch (kind) { case Contacts.KIND_PHONE: return resources.getStringArray(android.R.array.phoneTypes); case Contacts.KIND_EMAIL: return resources.getStringArray(android.R.array.emailAddressTypes); case Contacts.KIND_POSTAL: return resources.getStringArray(android.R.array.postalAddressTypes); case Contacts.KIND_IM: return resources.getStringArray(android.R.array.imProtocols); case Contacts.KIND_ORGANIZATION: return resources.getStringArray(android.R.array.organizationTypes); // case EditEntry.KIND_CONTACT: // return resources.getStringArray(R.array.otherLabels); } return null; }
public ContactItemListAdapter(Context context) { super(context, R.layout.contacts_list_item, null, false); mContext = context; mAlphabet = context.getString(R.string.fast_scroll_alphabet); // com.android.internal. mUnknownNameText = context.getText(android.R.string.unknownName); switch (mMode) { case MODE_PICK_POSTAL: mLocalizedLabels = getLabelsForKind(mContext, Contacts.KIND_POSTAL); break; default: mLocalizedLabels = getLabelsForKind(mContext, Contacts.KIND_PHONE); break; } // if ((mMode & MODE_MASK_SHOW_PHOTOS) == MODE_MASK_SHOW_PHOTOS) { // mDisplayPhotos = true; // setViewResource(R.layout.contacts_list_item_photo); // mBitmapCache = new SparseArray<SoftReference<Bitmap>>(); // } }
/** * Looks up a contacts id, given their address (phone number in this case). * Returns null if not found */ public static String getPersonIdFromPhoneNumber(Context context, String address) { if (address == null) return null; Cursor cursor = context.getContentResolver().query( Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, address), new String[] { Contacts.Phones.PERSON_ID }, null, null, null); if (cursor != null) { try { if (cursor.getCount() > 0) { cursor.moveToFirst(); Long id = Long.valueOf(cursor.getLong(0)); // Log.v("Found person: " + id); return (String.valueOf(id)); } } finally { cursor.close(); } } return null; }
boolean isExcludedType(Vector<Integer> vExTypesCode, String sNumber, Context oContext) { Uri contactRef = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, sNumber); final String[] PHONES_PROJECTION = new String[] { People.Phones.NUMBER, // 0 People.Phones.TYPE, // 1 }; Cursor phonesCursor = oContext.getContentResolver().query(contactRef, PHONES_PROJECTION, null, null, null); if (phonesCursor != null) { while (phonesCursor.moveToNext()) { final int type = phonesCursor.getInt(1); if(vExTypesCode.contains(Integer.valueOf(type))) return true; } phonesCursor.close(); } return false; }
/** * Factory method to start query with a number */ public static CallerInfoAsyncQuery startQuery(int token, Context context, String number, String number2, OnQueryCompleteListener listener, Object cookie) { //contruct the URI object and start Query. String number_search = number; if (number.contains("&")) number_search = number.substring(0,number.indexOf("&")); Uri contactRef = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, number_search); CallerInfoAsyncQuery c = new CallerInfoAsyncQuery(); c.allocate(context, contactRef); if (DBG) log("starting query for number: " + number + " handler: " + c.toString()); //create cookieWrapper, start query CookieWrapper cw = new CookieWrapper(); cw.listener = listener; cw.cookie = cookie; cw.number = number; cw.number2 = number2; cw.event = EVENT_NEW_QUERY; c.mHandler.startQuery (token, cw, contactRef, null, null, null, null); return c; }
public CallerIDResult getContact(String phoneNumber) throws NoResultException { final Uri uri = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, Uri.encode(phoneNumber)); final ContentResolver contentResolver = application.getContentResolver(); final Cursor cursor = contentResolver.query(uri,GET_CONTACT_PROJECTION,null,null,null); try{ if(cursor.moveToNext()){ CallerIDResult ret = new CallerIDResult(); ret.setPhoneNumber(cursor.getString(NUMBER_COLUMN_INDEX)); ret.setName(cursor.getString(DISPLAY_NAME_COLUMN_INDEX)); return ret; }else{ throw new NoResultException(); } }finally{ cursor.close(); } }
final void addContact(String[] names, String[] phoneNumbers, String[] emails, String note, String address, String org, String title) { // Only use the first name in the array, if present. Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT, Contacts.CONTENT_URI); intent.setType(Contacts.People.CONTENT_ITEM_TYPE); putExtra(intent, Contacts.Intents.Insert.NAME, names != null ? names[0] : null); int phoneCount = Math.min(phoneNumbers != null ? phoneNumbers.length : 0, Contents.PHONE_KEYS.length); for (int x = 0; x < phoneCount; x++) { putExtra(intent, Contents.PHONE_KEYS[x], phoneNumbers[x]); } int emailCount = Math.min(emails != null ? emails.length : 0, Contents.EMAIL_KEYS.length); for (int x = 0; x < emailCount; x++) { putExtra(intent, Contents.EMAIL_KEYS[x], emails[x]); } putExtra(intent, Contacts.Intents.Insert.NOTES, note); putExtra(intent, Contacts.Intents.Insert.POSTAL, address); putExtra(intent, Contacts.Intents.Insert.COMPANY, org); putExtra(intent, Contacts.Intents.Insert.JOB_TITLE, title); launchIntent(intent); }
/** * Turns a converts the sender, either phone number of optionally the * contact name, into associated Morse code timings. * * (Uses deprecated APIs to support pre-2.0 devices.) * @param context * @param sender * @return <pre>ArrayList</pre> of <pre>Long</pre>s of off/on vibration intervals */ private ArrayList<Long> convertSenderToVibrations(Context context, String sender) { if (this.settings.getBoolean(context.getString(R.string.preference_lookup_contact_name), true)) { final String[] projection = new String[] { Contacts.PeopleColumns.DISPLAY_NAME }; final String selection = Contacts.Phones.NUMBER + " = " + sender; final Cursor results = context.getContentResolver().query(Contacts.Phones.CONTENT_URI, projection, selection, null, Contacts.ContactMethods.PERSON_ID); if (results.moveToFirst()) { return this.convertToVibrations(results.getString(results.getColumnIndex(Contacts.PeopleColumns.DISPLAY_NAME))); } } return this.convertToVibrations(sender, true); }
/** * For versions before Honeycomb, we get all the contact info from the same table. */ public void preHoneycombGetContactInfo(Cursor cursor) { if (cursor.moveToFirst()) { contactName = guardCursorGetString(cursor, NAME_INDEX); phoneNumber = guardCursorGetString(cursor, NUMBER_INDEX); int contactId = cursor.getInt(PERSON_INDEX); Uri cUri = ContentUris.withAppendedId(Contacts.People.CONTENT_URI, contactId); contactPictureUri = cUri.toString(); String emailId = guardCursorGetString(cursor, EMAIL_INDEX); emailAddress = getEmailAddress(emailId); } }
protected ContactPicker(ComponentContainer container, Uri intentUri) { super(container); activityContext = container.$context(); if (SdkLevel.getLevel() >= SdkLevel.LEVEL_HONEYCOMB_MR1 && intentUri.equals(Contacts.People.CONTENT_URI)) { this.intentUri = HoneycombMR1Util.getContentUri(); } else if (SdkLevel.getLevel() >= SdkLevel.LEVEL_HONEYCOMB_MR1 && intentUri.equals(Contacts.Phones.CONTENT_URI)) { this.intentUri = HoneycombMR1Util.getPhoneContentUri(); } else { this.intentUri = intentUri; } }
/** * Email address getter for pre-Honeycomb. */ protected String getEmailAddress(String emailId) { int id; try { id = Integer.parseInt(emailId); } catch (NumberFormatException e) { return ""; } String data = ""; String where = "contact_methods._id = " + id; String[] projection = { Contacts.ContactMethods.DATA }; Cursor cursor = activityContext.getContentResolver().query( Contacts.ContactMethods.CONTENT_EMAIL_URI, projection, where, null, null); try { if (cursor.moveToFirst()) { data = guardCursorGetString(cursor, 0); } } finally { cursor.close(); } // this extra check for null might be redundant, but we given that there are mysterious errors // on some phones, we'll leave it in just to be extra careful return ensureNotNull(data); }
private static InputStream openMedia(Form form, String mediaPath, MediaSource mediaSource) throws IOException { switch (mediaSource) { case ASSET: return getAssetsIgnoreCaseInputStream(form,mediaPath); case REPL_ASSET: return new FileInputStream(replAssetPath(mediaPath)); case SDCARD: return new FileInputStream(mediaPath); case FILE_URL: case URL: return new URL(mediaPath).openStream(); case CONTENT_URI: return form.getContentResolver().openInputStream(Uri.parse(mediaPath)); case CONTACT_URI: // Open the photo for the contact. InputStream is = null; if (SdkLevel.getLevel() >= SdkLevel.LEVEL_HONEYCOMB_MR1) { is = HoneycombMR1Util.openContactPhotoInputStreamHelper(form.getContentResolver(), Uri.parse(mediaPath)); } else { is = Contacts.People.openContactPhotoInputStream(form.getContentResolver(), Uri.parse(mediaPath)); } if (is != null) { return is; } // There's no photo for the contact. throw new IOException("Unable to open contact photo " + mediaPath + "."); } throw new IOException("Unable to open media " + mediaPath + "."); }
/** * Retrieves all contacts from the SIM card. * * @return ArrayList containing Contact objects from the stored SIM information */ public ArrayList<Contact> get() { final String[] simProjection = new String[] { Contacts.PeopleColumns.NAME, Contacts.PhonesColumns.NUMBER, android.provider.BaseColumns._ID }; Cursor results = resolver.query( simUri, simProjection, null, null, android.provider.Contacts.PeopleColumns.NAME ); final ArrayList<Contact> simContacts = new ArrayList<>(); if (results != null) { if (results.getCount() > 0) { while (results.moveToNext()) { final Contact simContact = new Contact( results.getString(results.getColumnIndex(android.provider.BaseColumns._ID)), results.getString(results.getColumnIndex(Contacts.PeopleColumns.NAME)), results.getString(results.getColumnIndex(Contacts.PhonesColumns.NUMBER)) ); simContacts.add(simContact); } } results.close(); } return simContacts; }
private void addContact(String name, String phone) { ContentValues values = new ContentValues(); values.put(Contacts.People.NUMBER, phone); values.put(Contacts.People.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM); values.put(Contacts.People.LABEL, name); values.put(Contacts.People.NAME, name); Uri dataUri = getContentResolver().insert(Contacts.People.CONTENT_URI, values); Uri updateUri = Uri.withAppendedPath(dataUri, Contacts.People.Phones.CONTENT_DIRECTORY); values.clear(); values.put(Contacts.People.Phones.TYPE, Contacts.People.TYPE_MOBILE); values.put(Contacts.People.NUMBER, phone); updateUri = getContentResolver().insert(updateUri, values); }
/** * {@inheritDoc} */ public View buildUI(DataType initData) { if (initData != null) { editText.setText(initData.getValue()); } ContentResolver cr = activity.getContentResolver(); List<String> contacts = new ArrayList<String>(); // Form an array specifying which columns to return. String[] projection = new String[] {People.NAME, People.NUMBER }; // Get the base URI for the People table in the Contacts content provider. Uri contactsUri = People.CONTENT_URI; // Make the query. Cursor cursor = cr.query(contactsUri, projection, // Which columns to return null, // Which rows to return (all rows) null, // Selection arguments (none) Contacts.People.DEFAULT_SORT_ORDER); if (cursor.moveToFirst()) { String name; String phoneNumber; int nameColumn = cursor.getColumnIndex(People.NAME); int phoneColumn = cursor.getColumnIndex(People.NUMBER); do { // Get the field values of contacts name = cursor.getString(nameColumn); phoneNumber = cursor.getString(phoneColumn); contacts.add(name + ": " + phoneNumber); } while (cursor.moveToNext()); } cursor.close(); String[] contactsStr = new String[]{}; ArrayAdapter<String> adapter = new ArrayAdapter<String>(activity, android.R.layout.simple_dropdown_item_1line, contacts.toArray(contactsStr)); editText.setAdapter(adapter); editText.setThreshold(1); return(editText); }
/** * Pick contact only from contacts with telephone numbers */ public static Intent pickContactWithPhone() { Intent intent; if (isSupportsContactsV2()) { intent = pickContact(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE); } else { // pre Eclair, use old contacts API intent = pickContact(Contacts.Phones.CONTENT_TYPE); } return intent; }
private Uri getContactContentUri() { if (isEclairOrLater()) { // ContactsContract.Contacts.CONTENT_URI return Uri.parse("content://com.android.contacts/contacts"); } else { return Contacts.People.CONTENT_URI; } }
/** * Pick contact from phone book * * @param scope You can restrict selection by passing required content type. */ public static Intent pickContact(String scope) { Intent intent; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ECLAIR) { intent = new Intent(Intent.ACTION_PICK, Contacts.People.CONTENT_URI); } else { intent = new Intent(Intent.ACTION_PICK, Uri.parse("content://com.android.contacts/contacts")); } if (!TextUtils.isEmpty(scope)) { intent.setType(scope); } return intent; }
protected String getEmailAddress(String emailId) { int id; try { id = Integer.parseInt(emailId); } catch (NumberFormatException e) { return ""; } String data = ""; String where = "contact_methods._id = " + id; String[] projection = { Contacts.ContactMethods.DATA }; Cursor cursor = activityContext.getContentResolver().query( Contacts.ContactMethods.CONTENT_EMAIL_URI, projection, where, null, null); try { if (cursor.moveToFirst()) { data = guardCursorGetString(cursor, 0); } } finally { cursor.close(); } // this extra check for null might be redundant, but we given that there are mysterious errors // on some phones, we'll leave it in just to be extra careful return ensureNotNull(data); }
private static InputStream openMedia(Form form, String mediaPath, MediaSource mediaSource) throws IOException { switch (mediaSource) { case ASSET: return form.getAssets().open(mediaPath); case REPL_ASSET: return new FileInputStream(replAssetPath(mediaPath)); case SDCARD: return new FileInputStream(mediaPath); case FILE_URL: case URL: return new URL(mediaPath).openStream(); case CONTENT_URI: return form.getContentResolver().openInputStream(Uri.parse(mediaPath)); case CONTACT_URI: // Open the photo for the contact. InputStream is = Contacts.People.openContactPhotoInputStream(form.getContentResolver(), Uri.parse(mediaPath)); if (is != null) { return is; } // There's no photo for the contact. throw new IOException("Unable to open contact photo " + mediaPath + "."); } throw new IOException("Unable to open media " + mediaPath + "."); }
private static InputStream openMedia(FormService formservice, String mediaPath, MediaSource mediaSource) throws IOException { switch (mediaSource) { case ASSET: return formservice.getAssets().open(mediaPath); case REPL_ASSET: return new FileInputStream(replAssetPath(mediaPath)); case SDCARD: return new FileInputStream(mediaPath); case FILE_URL: case URL: return new URL(mediaPath).openStream(); case CONTENT_URI: return formservice.getContentResolver().openInputStream(Uri.parse(mediaPath)); case CONTACT_URI: // Open the photo for the contact. InputStream is = Contacts.People.openContactPhotoInputStream(formservice.getContentResolver(), Uri.parse(mediaPath)); if (is != null) { return is; } // There's no photo for the contact. throw new IOException("Unable to open contact photo " + mediaPath + "."); } throw new IOException("Unable to open media " + mediaPath + "."); }
public static InputStream loadContactPhoto(ContentResolver cr, long id, long photo_id) { Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id); InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(cr, uri); if (input != null) { return input; } byte[] photoBytes = null; Uri photoUri = ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, photo_id); Cursor c = cr.query(photoUri, new String[]{ContactsContract.CommonDataKinds.Photo.PHOTO}, null, null, null); try { if (c.moveToFirst()) { photoBytes = c.getBlob(0); } } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } finally { c.close(); } if (photoBytes != null) { return new ByteArrayInputStream(photoBytes); } return null; }
/** * Checks whether the contact refered to by the URI contains any postal contact methods. * Postal contact methods usually can be geocoded and thus can be used for proximity alerts. * * @param uri A android.provider.Contacts.People.CONTENT_URI with id. * @return */ protected static boolean doesContactUriContainLocationInfoSDK3(Context ctx, Uri uri) throws RuntimeException { Long personId = ContentUris.parseId(uri); if( personId < 0 ){ // Whoops, bad data! Bail. Exception exp = (Exception)(new Exception("URI missing id.").fillInStackTrace()); Log.e(TAG, "ERR0003F URI missing id."); ErrorUtil.handleExceptionNotifyUserAndThrow("ERR0003F", exp, ctx); } // ****************************************************** // Find the postal address that the user wants to use // ****************************************************** // Get a list of the postal addresses Cursor mContactMethodPostalCursor = ctx.getContentResolver().query(ContactMethods.CONTENT_URI, ContactMethodProjectionGps.CONTACT_METHODS_PROJECTION, ContactMethods.PERSON_ID+"=? AND "+ContactMethodsColumns.KIND+"=?", new String[]{personId.toString(), String.valueOf(Contacts.KIND_POSTAL)}, null); int count = mContactMethodPostalCursor.getCount(); mContactMethodPostalCursor.close(); // Zero postal addresses if( count < 1){ // No postal addresses exist, so no GPS locations can exist, right? return false; } return true; }
private void resolveForPerson(ArrayList<OverlayItem> overlayItems) { personId = ContentUris.parseId(itr.next()); if( personId < 0 ){ // Whoops, bad data! Bail. Exception exp = (Exception)(new Exception("Missing or incomplete Contacts.People.CONTENT_URI.").fillInStackTrace()); Log.e(TAG, "ERR0001H", exp); ErrorUtil.handleExceptionNotifyUserAndThrow("ERR0001H", exp, mContext); } // ****************************************************** // Find the postal address that the user wants to use // ****************************************************** // Get a list of the postal addresses mContactMethodPostalCursor = mContext.getContentResolver().query(ContactMethods.CONTENT_URI, ContactMethodProjectionGps.CONTACT_METHODS_PROJECTION, // TODO: This won't work for Androic 2.x and above phones. ContactMethods.PERSON_ID+"=? AND "+ContactMethodsColumns.KIND+"=?", new String[]{personId.toString(), String.valueOf(Contacts.KIND_POSTAL)}, null); if(mContactMethodPostalCursor.moveToNext()){ Uri postalContactMethodUri = ContentUris.withAppendedId(ContactMethods.CONTENT_URI, mContactMethodPostalCursor.getInt(ContactMethodProjectionGps.CONTACT_M_ID_INDEX)); mContactData = mContactMethodPostalCursor.getString(ContactMethodProjectionGps.CONTACT_M_DATA_INDEX); mGeocodeAddressPart.resolveAddressPosition(mContactData, postalContactMethodUri, this); }else{ mContactMethodPostalCursor.close(); personId = -1l; if(itr.hasNext()){ resolveForPerson(overlayItems); }else{ mListener.onOverlayItemsResolved(overlayItems); } } }
protected Uri constructReturnData(Long personId, Long contactMethodId){ Builder builder = ContentUris.appendId(Contacts.People.CONTENT_URI.buildUpon(), personId); builder.appendPath(Contacts.People.ContactMethods.CONTENT_DIRECTORY); builder.appendPath(contactMethodId.toString()); Uri returnData = builder.build(); return returnData; }
/** * Pick contact only from contacts with telephone numbers */ @SuppressWarnings("deprecation") public static Intent newPickContactWithPhoneIntent() { Intent intent; if (isContacts2ApiSupported()) { intent = newPickContactIntent(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE); } else { // pre Eclair, use old contacts API intent = newPickContactIntent(Contacts.Phones.CONTENT_TYPE); } return intent; }
/** * Looks up a contacts display name by contact id - if not found, the * address (phone number) will be formatted and returned instead. */ public static String getPersonName(Context context, String id, String address) { if (id == null) { if (address != null) { // Log.v("Contact not found, formatting number"); return PhoneNumberUtils.formatNumber(address); } else { return null; } } Cursor cursor = context.getContentResolver().query(Uri.withAppendedPath(Contacts.People.CONTENT_URI, id), new String[] { PeopleColumns.DISPLAY_NAME }, null, null, null); if (cursor != null) { try { if (cursor.getCount() > 0) { cursor.moveToFirst(); String name = cursor.getString(0); // Log.v("Contact Display Name: " + name); return name; } } finally { cursor.close(); } } if (address != null) { // Log.v("Contact not found, formatting number"); return PhoneNumberUtils.formatNumber(address); } return null; }
/** * Looks up a contats photo by their contact id, returns a byte array that * represents their photo (or null if not found) */ public static byte[] getPersonPhoto(Context context, String id) { if (id == null) return null; if ("0".equals(id)) return null; byte photo[] = null; // TODO: switch to API method: // Contacts.People.loadContactPhoto(arg0, arg1, arg2, arg3) 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; } } } finally { cursor.close(); } } return photo; }