Java Code Examples for android.provider.ContactsContract.CommonDataKinds.Phone#NUMBER
The following examples show how to use
android.provider.ContactsContract.CommonDataKinds.Phone#NUMBER .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExpandableList2.java From codeexamples-android with Eclipse Public License 1.0 | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set up our adapter mAdapter = new MyExpandableListAdapter( this, android.R.layout.simple_expandable_list_item_1, android.R.layout.simple_expandable_list_item_1, new String[] { Contacts.DISPLAY_NAME }, // Name for group layouts new int[] { android.R.id.text1 }, new String[] { Phone.NUMBER }, // Number for child layouts new int[] { android.R.id.text1 }); setListAdapter(mAdapter); mQueryHandler = new QueryHandler(this, mAdapter); // Query for people mQueryHandler.startQuery(TOKEN_GROUP, null, Contacts.CONTENT_URI, CONTACTS_PROJECTION, Contacts.HAS_PHONE_NUMBER + "=1", null, null); }
Example 2
Source File: HoneycombMR1Util.java From appinventor-extensions with Apache License 2.0 | 5 votes |
/** * Get the NAME_PROJECTION for PhoneNumberPicker. */ public static String[] getNameProjection() { String[] nameProjection = { Data.CONTACT_ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.PHOTO_THUMBNAIL_URI, Phone.NUMBER, }; return nameProjection; }
Example 3
Source File: HoneycombMR1Util.java From appinventor-extensions with Apache License 2.0 | 5 votes |
/** * Get the DATA_PROJECTION for ContactPicker and PhoneNumberPicker. */ public static String[] getDataProjection() { String[] dataProjection = { Data.MIMETYPE, Email.ADDRESS, Email.TYPE, Phone.NUMBER, Phone.TYPE, }; return dataProjection; }
Example 4
Source File: BaseRecipientAdapter.java From ChipsLibrary with Apache License 2.0 | 5 votes |
private Cursor doQuery(final CharSequence constraint,final int limit,final Long directoryId) { String constraintStr=constraint.toString(); final Uri.Builder builder; String selection=null; String[] selectionArgs=null; if(mQuery!=Queries.PHONE) builder=mQuery.getContentFilterUri().buildUpon().appendPath(constraintStr); else { builder=mQuery.getContentUri().buildUpon(); // search for either contact name or its phone number selection=Contacts.DISPLAY_NAME+" LIKE ? OR "+Phone.NUMBER+" LIKE ?"; constraintStr="%"+constraintStr+"%"; selectionArgs=new String[] {constraintStr,constraintStr}; } builder.appendQueryParameter(ContactsContract.LIMIT_PARAM_KEY,String.valueOf(limit+ALLOWANCE_FOR_DUPLICATES)); if(directoryId!=null) builder.appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY,String.valueOf(directoryId)); if(mAccount!=null) { builder.appendQueryParameter(PRIMARY_ACCOUNT_NAME,mAccount.name); builder.appendQueryParameter(PRIMARY_ACCOUNT_TYPE,mAccount.type); } // final long start = System.currentTimeMillis(); final Uri uri=builder.build(); final Cursor cursor=mContentResolver.query(uri,mQuery.getProjection(),selection,selectionArgs,null); // final long end = System.currentTimeMillis(); // if (DEBUG) { // Log.d(TAG, "Time for autocomplete (query: " + constraint + ", directoryId: " + directoryId // + ", num_of_results: " + (cursor != null ? cursor.getCount() : "null") + "): " + (end - start) // + " ms"); // } return cursor; }
Example 5
Source File: RecipientAlternatesAdapter.java From ChipsLibrary with Apache License 2.0 | 5 votes |
private static Cursor doQuery(final CharSequence constraint,final int limit,final Long directoryId,final Account account,final ContentResolver resolver,final Query query) { String constraintStr=constraint.toString(); final Uri.Builder builder; String selection=null; String[] selectionArgs=null; if(query!=Queries.PHONE) builder=query.getContentFilterUri().buildUpon().appendPath(constraintStr).appendQueryParameter(ContactsContract.LIMIT_PARAM_KEY,String.valueOf(limit+BaseRecipientAdapter.ALLOWANCE_FOR_DUPLICATES)); else { builder=query.getContentUri().buildUpon().appendQueryParameter(ContactsContract.LIMIT_PARAM_KEY,String.valueOf(limit+BaseRecipientAdapter.ALLOWANCE_FOR_DUPLICATES)); selection=Contacts.DISPLAY_NAME+" LIKE ? OR "+Phone.NUMBER+" LIKE ?"; constraintStr="%"+constraintStr+"%"; selectionArgs=new String[] {constraintStr,constraintStr}; } if(directoryId!=null) builder.appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY,String.valueOf(directoryId)); if(account!=null) { builder.appendQueryParameter(BaseRecipientAdapter.PRIMARY_ACCOUNT_NAME,account.name); builder.appendQueryParameter(BaseRecipientAdapter.PRIMARY_ACCOUNT_TYPE,account.type); } // final long start = System.currentTimeMillis(); final Uri uri=builder.build(); final Cursor cursor=resolver.query(uri,query.getProjection(),selection,selectionArgs,null); // final long end = System.currentTimeMillis(); // if (DEBUG) { // Log.d(TAG, "Time for autocomplete (query: " + constraint + ", directoryId: " + directoryId // + ", num_of_results: " + (cursor != null ? cursor.getCount() : "null") + "): " + (end - start) // + " ms"); // } return cursor; }
Example 6
Source File: List3.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Get a cursor with all phones Cursor c = getContentResolver().query(Phone.CONTENT_URI, PHONE_PROJECTION, null, null, null); startManagingCursor(c); // Map Cursor columns to views defined in simple_list_item_2.xml SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, c, new String[] { Phone.TYPE, Phone.NUMBER }, new int[] { android.R.id.text1, android.R.id.text2 }); //Used to display a readable string for the phone type adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { public boolean setViewValue(View view, Cursor cursor, int columnIndex) { //Let the adapter handle the binding if the column is not TYPE if (columnIndex != COLUMN_TYPE) { return false; } int type = cursor.getInt(COLUMN_TYPE); String label = null; //Custom type? Then get the custom label if (type == Phone.TYPE_CUSTOM) { label = cursor.getString(COLUMN_LABEL); } //Get the readable string String text = (String) Phone.getTypeLabel(getResources(), type, label); //Set text ((TextView) view).setText(text); return true; } }); setListAdapter(adapter); }
Example 7
Source File: ContactAccessor.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
/*** * If the code below looks shitty to you, that's because it was taken * directly from the Android source, where shitty code is all you get. */ public Cursor getCursorForRecipientFilter(CharSequence constraint, ContentResolver mContentResolver) { final String SORT_ORDER = Contacts.TIMES_CONTACTED + " DESC," + Contacts.DISPLAY_NAME + "," + Contacts.Data.IS_SUPER_PRIMARY + " DESC," + Phone.TYPE; final String[] PROJECTION_PHONE = { Phone._ID, // 0 Phone.CONTACT_ID, // 1 Phone.TYPE, // 2 Phone.NUMBER, // 3 Phone.LABEL, // 4 Phone.DISPLAY_NAME, // 5 }; String phone = ""; String cons = null; if (constraint != null) { cons = constraint.toString(); if (RecipientsAdapter.usefulAsDigits(cons)) { phone = PhoneNumberUtils.convertKeypadLettersToDigits(cons); if (phone.equals(cons) && !PhoneNumberUtils.isWellFormedSmsAddress(phone)) { phone = ""; } else { phone = phone.trim(); } } } Uri uri = Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri.encode(cons)); String selection = String.format("%s=%s OR %s=%s OR %s=%s", Phone.TYPE, Phone.TYPE_MOBILE, Phone.TYPE, Phone.TYPE_WORK_MOBILE, Phone.TYPE, Phone.TYPE_MMS); Cursor phoneCursor = mContentResolver.query(uri, PROJECTION_PHONE, null, null, SORT_ORDER); if (phone.length() > 0) { ArrayList result = new ArrayList(); result.add(Integer.valueOf(-1)); // ID result.add(Long.valueOf(-1)); // CONTACT_ID result.add(Integer.valueOf(Phone.TYPE_CUSTOM)); // TYPE result.add(phone); // NUMBER /* * The "\u00A0" keeps Phone.getDisplayLabel() from deciding * to display the default label ("Home") next to the transformation * of the letters into numbers. */ result.add("\u00A0"); // LABEL result.add(cons); // NAME ArrayList<ArrayList> wrap = new ArrayList<ArrayList>(); wrap.add(result); ArrayListCursor translated = new ArrayListCursor(PROJECTION_PHONE, wrap); return new MergeCursor(new Cursor[] { translated, phoneCursor }); } else { return phoneCursor; } }
Example 8
Source File: ContactAccessor.java From Silence with GNU General Public License v3.0 | 4 votes |
/*** * If the code below looks shitty to you, that's because it was taken * directly from the Android source, where shitty code is all you get. */ public Cursor getCursorForRecipientFilter(CharSequence constraint, ContentResolver mContentResolver) { final String SORT_ORDER = Contacts.TIMES_CONTACTED + " DESC," + Contacts.DISPLAY_NAME + "," + Contacts.Data.IS_SUPER_PRIMARY + " DESC," + Phone.TYPE; final String[] PROJECTION_PHONE = { Phone._ID, // 0 Phone.CONTACT_ID, // 1 Phone.TYPE, // 2 Phone.NUMBER, // 3 Phone.LABEL, // 4 Phone.DISPLAY_NAME, // 5 }; String phone = ""; String cons = null; if (constraint != null) { cons = constraint.toString(); if (RecipientsAdapter.usefulAsDigits(cons)) { phone = PhoneNumberUtils.convertKeypadLettersToDigits(cons); if (phone.equals(cons) && !PhoneNumberUtils.isWellFormedSmsAddress(phone)) { phone = ""; } else { phone = phone.trim(); } } } Uri uri = Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri.encode(cons)); String selection = String.format("%s=%s OR %s=%s OR %s=%s", Phone.TYPE, Phone.TYPE_MOBILE, Phone.TYPE, Phone.TYPE_WORK_MOBILE, Phone.TYPE, Phone.TYPE_MMS); Cursor phoneCursor = mContentResolver.query(uri, PROJECTION_PHONE, null, null, SORT_ORDER); if (phone.length() > 0) { ArrayList result = new ArrayList(); result.add(-1); // ID result.add((long) -1); // CONTACT_ID result.add(Phone.TYPE_CUSTOM); // TYPE result.add(phone); // NUMBER /* * The "\u00A0" keeps Phone.getDisplayLabel() from deciding * to display the default label ("Home") next to the transformation * of the letters into numbers. */ result.add("\u00A0"); // LABEL result.add(cons); // NAME ArrayList<ArrayList> wrap = new ArrayList<ArrayList>(); wrap.add(result); ArrayListCursor translated = new ArrayListCursor(PROJECTION_PHONE, wrap); return new MergeCursor(new Cursor[] { translated, phoneCursor }); } else { return phoneCursor; } }
Example 9
Source File: ContactDetailFragment.java From Contacts with MIT License | 4 votes |
@Override protected Contact doInBackground(Cursor... params) { mContact = new Contact(); mContact.setLookupKey(mLookupKey); Cursor cursor = params[0]; if (cursor != null && !cursor.isClosed()) { while (cursor.moveToNext()) { long id = cursor.getLong(0); String name = cursor.getString(1); String firstName = cursor.getString(2); String lastName = cursor.getString(3); String photo = cursor.getString(4); String photoThumb = cursor.getString(5); int starred = cursor.getInt(6); mContact.setId(id); if (name != null) mContact.setName(name); if (firstName != null) mContact.setFirstName(firstName); if (lastName != null) mContact.setLastName(lastName); if (photo != null) mContact.setPhoto(photo); if (photoThumb != null) mContact.setPhotoThumb(photoThumb); mContact.setStarred(starred == 1); } cursor.close(); } String[] projection = { Phone.TYPE, Phone.NORMALIZED_NUMBER, Phone.LABEL, Phone.NUMBER }; String selection = Phone.LOOKUP_KEY + " = ?"; String[] parameters = new String[] { mLookupKey }; Cursor phones = getActivity().getContentResolver().query(Phone.CONTENT_URI, projection, selection, parameters, null); while (phones.moveToNext()) { if (phones.getString(1) != null) mContact.addPhoneNumber(phones.getInt(0), phones.getString(1), phones.getString(2)); else mContact.addPhoneNumber(phones.getInt(0), phones.getString(3), phones.getString(2)); } phones.close(); // Same process for the names projection = new String[] { Email.TYPE, Email.ADDRESS }; selection = Email.LOOKUP_KEY + " = ?"; parameters = new String[] { mLookupKey }; Cursor emails = getActivity().getContentResolver().query(Email.CONTENT_URI, projection, selection, parameters, null); while (emails.moveToNext()) { mContact.addEmailAddress(emails.getInt(0), emails.getString(1)); } return mContact; }