I wonder if i am in the right path. The emulator keeps showing the message xxx.app stopped exectedly and ask to force shutdown. Here are the codes
package fypj.ContactList;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.Contacts.People;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class ContactList extends Activity {
ListView ContactsLV;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ContactsLV = (ListView)findViewById(R.id.ContactsLV);
populateContactList();
}
public void contentProvider(ContentResolver getContentResolver){
ContentValues values = new ContentValues();
values.put(Phone.DISPLAY_NAME, "Jaslyn");
values.put(Phone.LABEL, "Jaslyn Goh");
values.put(Phone.STARRED, 1);
Uri uri = getContentResolver().insert(Phone.CONTENT_URI, values);
Uri phoneUri = null;
Uri emailUri = null;
phoneUri = Uri.withAppendedPath(uri, People.ContactMethods.CONTENT_DIRECTORY);
values.clear();
values.put(Phone.TYPE, Phone.TYPE_MOBILE);
values.put(Phone.NUMBER, "91289161");
getContentResolver().insert(phoneUri, values);
emailUri = Uri.withAppendedPath(uri, People.ContactMethods.CONTENT_DIRECTORY );
values.clear();
//values.put(People.ContactMethods.KIND, Contacts.KIND_EMAIL);
values.put(People.ContactMethods.DATA, "asd@hotmail.com");
values.put(People.ContactMethods.TYPE, People.ContactMethods.TYPE_HOME);
getContentResolver().insert(emailUri, values);
}
public void populateContactList(){
Cursor c = getContacts();
String[] contacts = new String[]{
ContactsContract.Data.DISPLAY_NAME,
//ContactsContract.Data.CONTACT_STATUS,
//ContactsContract.Contacts.STARRED,
};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.main,
c, contacts, new int[] {R.id.ContactsLV});
//ContactsLV.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, contacts));
ContactsLV.setAdapter(adapter);
}
private Cursor getContacts(){
Uri uri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[] {
//ContactsContract.Contacts.开发者_如何学Go_ID,
ContactsContract.Contacts.DISPLAY_NAME,
};
String[] selectionArgs = null;
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
//String selection = null;
String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'";
return managedQuery(uri, projection,selection,selectionArgs, sortOrder);
}
}
Logcat
03-21 08:32:54.013: ERROR/InputDispatcher(64): Received spurious receive callback for unknown input channel. fd=167, events=0x8
03-21 08:32:54.013: ERROR/InputDispatcher(64): Received spurious receive callback for unknown input channel. fd=170, events=0x8
03-21 08:32:54.013: ERROR/InputDispatcher(64): Received spurious receive callback for unknown input channel. fd=178, events=0x8
03-21 08:32:54.023: ERROR/InputDispatcher(64): Received spurious receive callback for unknown input channel. fd=188, events=0x8
03-21 08:33:03.053: ERROR/TelephonyManager(64): Hidden constructor called more than once per process!
03-21 08:33:03.053: ERROR/TelephonyManager(64): Original: android, new: android
03-21 08:33:45.002: ERROR/libEGL(64): called unimplemented OpenGL ES API
03-21 08:33:45.002: ERROR/libEGL(64): called unimplemented OpenGL ES API
03-21 08:33:45.002: ERROR/libEGL(64): called unimplemented OpenGL ES API
03-21 08:33:45.002: ERROR/libEGL(64): called unimplemented OpenGL ES API
03-21 08:33:45.002: ERROR/libEGL(64): called unimplemented OpenGL ES API
03-21 08:33:45.011: ERROR/libEGL(64): called unimplemented OpenGL ES API
03-21 08:33:45.011: ERROR/libEGL(64): called unimplemented OpenGL ES API
03-21 08:33:45.021: ERROR/libEGL(64): called unimplemented OpenGL ES API
Double check above line
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.main,
c, contacts, new int[] {R.id.ContactsLV});
with the SimpleCursorAdapter (Context context, int layout, Cursor c, String[] from, int[] to, int flags)
You just need to change the layout integer .just have a look at http://thinkandroid.wordpress.com/2010/01/09/simplecursoradapters-and-listviews
The logcat segment that you have posted does not have a specific error stack trace in it. But following are the things you could check:
- Check that the permission is right. You need to have Read contacts use permission.
- You will need the column ID selected in projection: ContactsContract.Contacts._ID
- As pointed by 100rabh, you need to look at the SimpleCursorAdapter. Specifically, the layout you pass should be the layout file containing the fields in which you want to populate the data and last integer array should correspond to the view id in which each of the column data has to be populated.
精彩评论