Is ContactsContract.Contacts by default empty? If so, how do I add some test data to it?
Otherwise, I must be doing something wrong/omitting something, as this Activity displays completely empty.
public class Authorize_Activity extends ListActivity {
Cursor mContacts;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Return all contacts, ordered by name
String[] projection = new String[] { ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME }; // Would like the phone num, too
mContacts = managedQuery(ContactsContract.Contacts.CONTENT_URI,
projection, null, null, ContactsContract.Contacts.DISPLAY_NAME);
// Display all contacts in a ListView
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1, mContacts,
new String[] { ContactsContract.Contacts.DISPLAY_NAME },
new int[] { android.R.id.text1 });
setListAdapter(mAdapter);
}
My understanding is that android’s simple_list_item_1 should provide the “View” so that I don’t need to call SetContentView().
But although my Activity is displaying, no data appears in it. So…am I just missing Contacts data, or is something more nefarious afoot?
Is this on an emulator?
If so then it wouldn’t surprise me if the contacts list is empty by default. Try using the emulator’s contacts / people app to add some fake contacts.