Android Contact List

Can anyone shed some light on how to get a contact list with Android ?.

I just want to get the same list as in the dialer app. But I get a lot of contacts that are not on the dialer list with the code below.

ContentResolver cr = getContentResolver(); Cursor cursor = cr.query(Contacts.People.CONTENT_URI, null, null, null, Contacts.ContactMethods.DEFAULT_SORT_ORDER); startManagingCursor(cursor); 

Thanks in advance.

+6
android list contact
source share
5 answers

Try this snippet:

 import android.app.ListActivity; import android.database.Cursor; import android.os.Bundle; import android.provider.ContactsContract; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.widget.SimpleCursorAdapter; public class ContactList extends ListActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Cursor cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, new String[] {Phone._ID, Phone.DISPLAY_NAME, Phone.NUMBER}, null, null, null); startManagingCursor(cursor); String[] from = new String[] { Phone.DISPLAY_NAME, Phone.NUMBER}; int[] to = new int[] { R.id.name_entry, R.id.number_entry}; SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.list_entry, cursor, from, to); this.setListAdapter(adapter); } } 

XML file:

list_entry.xml

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="6dip"> <TextView android:id="@+id/name_entry" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" android:gravity="center_vertical" android:textSize="18dip"/> <TextView android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" android:id="@+id/number_entry" android:singleLine="true" android:ellipsize="marquee" android:textSize="18dip"/> </LinearLayout> 
+6
source share

What you have seems beautiful. Could you talk about the "large number of contacts that are not on the dialer list"? Is that what Android makes up people? Or do you see people with email addresses, but not phone numbers (which may not appear in Dialer)?

Please note that Contacts.People for Android 1.6 and below. This provider has been deprecated since Android 2.0, replacing the ContactsContract provider set.

+2
source share

This is the base implementation of the Android contact list.

+1
source share

Ok, thanks for the answer first. Just to shed light on this.

I just wanted to receive emails only for contacts on my phone. Group "MyContacts". I saw that this concerns the ContactList group activity.

I ended up doing something like this:

 c = cr.query(myGroupUri, mEmailsProjection, null, null, null); .... c.close(); c = cr.query( Contacts.ContactMethods.CONTENT_URI, mContactsProjection, contactIds, null, null ); .... c.close(); 

First requested a group, and then an email table.

0
source share

try using the intent to go to your contact list

  startActivityForResult( new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI),1);} 
0
source share

All Articles