EDIT: The code works. This was a problem with Eclipse, and the code displays the output in logcat, as intended.
Android 2.3.3
I am new to using content providers. I just want to try an example of extracting contacts from my phone. I saw some examples, but no one worked for me when I tried this through my SAMSUNG Mobile.
Here is the code I used ...
public class Class_Add_Contact extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_contact);
readContacts();
}
private void readContacts() {
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,null, null);
while (cur.moveToNext()) {
String name =cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String phoneNumber = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
System.out.println(name + " " + phoneNumber);
}
}
}
The code seems fine, but the numbers are not displayed in the logarithm. What could be wrong?
source
share