公共类MainActivity扩展Activity { /** 在第一次创建活动时调用。 * /
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] projection = new String[]{
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.PhoneLookup.NUMBER
};
Cursor c = this.getContentResolver().query(Contacts.Phones.CONTENT_URI, projection, null, null, ContactsContract.Contacts.DISPLAY_NAME + " ASC");
c.moveToFirst();
int nameColumn = c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
int phoneColumn = c.getColumnIndex( ContactsContract.PhoneLookup.NUMBER);
if( c.getCount() > 0 ) {
do{
String name = c.getString(nameColumn);
String phoneNumber = c.getString(phoneColumn);
Toast.makeText(this, name+":"+phoneNumber, Toast.LENGTH_SHORT).show();
} while(c.moveToNext());
}
}