Android联系人列表
任何人都可以阐明如何从android获取联系人列表?Android联系人列表
我只想得到与拨号程序中相同的列表。但即时消息得到大量的联系人不在拨号列表中,下面的代码。
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(Contacts.People.CONTENT_URI, null, null, null, Contacts.ContactMethods.DEFAULT_SORT_ORDER);
startManagingCursor(cursor);
在此先感谢。
你看起来很好。你能否详细说明“获得大量不在拨号器列表中的联系人”? Android是在编造人吗?或者您是否看到带有电子邮件地址但没有电话号码的人(因此可能无法在拨号器中显示)?
请注意,Contacts.People
适用于Android 1.6及更低版本。该提供者已被弃用,从Android 2.0开始,取而代之的是ContactsContract
提供者。
那么,首先感谢您的答案。只是为了阐明这一点。
我只想给我的手机上的联系人发送电子邮件。 “我的联系人”组。我看到这是ContactList Activity使用的组。
我做完somethig这样的:
c = cr.query(myGroupUri, mEmailsProjection, null, null, null);
....
c.close();
c = cr.query(
Contacts.ContactMethods.CONTENT_URI,
mContactsProjection, contactIds, null, null
);
....
c.close();
只需查询该组第一,然后邮件表。
试试这个片断:
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文件是:
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>
要求使用权限>,否则它是有用的。 – 2011-06-08 10:32:09
startManagingCursor已被弃用... – drulabs 2011-12-26 10:28:59
@KKD:应该替换它吗? – 2013-01-26 02:15:20
尝试使用意图去到联系人列表
startActivityForResult(new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI),1);}
我想是因为他们希望1.6的兼容性很多开发者不会使用ContactsContract ... – Eno 2010-08-10 16:02:25