How to get a contact’s facebook id or url from native contacts / content resolver?

Got the reply from on the Google Group (http://groups.google.com/group/android-developers/browse_thread/thread/95110dd7a1e1e0b4): Access to Facebook friends via the contacts provider is restricted to a handful of system apps by the provider itself. Other applications cannot read that data. Therefore now I fetch an cache all contact names/id mappings via FB Graph api (http://graph.facebook.com/me/friends) and use that for the … Read more

Android get all contacts telephone number in ArrayList

ContentResolver cr = mContext.getContentResolver(); //Activity/Application android.content.Context Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); if(cursor.moveToFirst()) { ArrayList<String> alContacts = new ArrayList<String>(); do { String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)); if(Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) { Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +” = ?”,new String[]{ id }, null); while (pCur.moveToNext()) { String contactNumber = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); alContacts.add(contactNumber); break; } pCur.close(); } } … Read more

Insert a new contact intent

You can choose whether you want to add the contact automatically, or open the add contact activity with pre-filled data: /** * Open the add-contact screen with pre-filled info * * @param context * Activity context * @param person * {@link Person} to add to contacts list */ public static void addAsContactConfirmed(final Context context, final … Read more

Pick a Number and Name From Contacts List in android app

Try following code it will help you: // You need below permission to read contacts <uses-permission android:name=”android.permission.READ_CONTACTS”/> // Declare static final int PICK_CONTACT=1; Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); startActivityForResult(intent, PICK_CONTACT); //code @Override public void onActivityResult(int reqCode, int resultCode, Intent data) { super.onActivityResult(reqCode, resultCode, data); switch (reqCode) { case (PICK_CONTACT) : if (resultCode == Activity.RESULT_OK) … Read more

Android: Retrieve contact name from phone number

Although this has already been answered, but here is the complete function to get the contact name from number. Hope it will help others: public static String getContactName(Context context, String phoneNumber) { ContentResolver cr = context.getContentResolver(); Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); Cursor cursor = cr.query(uri, new String[]{PhoneLookup.DISPLAY_NAME}, null, null, null); if (cursor == null) { … Read more