Tuesday, 6 August 2013

unable to get the email address

unable to get the email address

This question is already asked Getting contact email by name but this is
not helpful for me.I have the following code for getting email address
unfortunately it is not working. anybody help to solve this.
ContentResolver cr = getContentResolver();
Cursor emailCur = cr.query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Email.Display_Name + " = ?",
new String[]{name}, null);
TextView tv2 = (TextView) findViewById(R.id.textView5);
while (emailCur.moveToNext()) {
String email = emailCur.getString(
emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
String emailType = emailCur.getString(
emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE));
tv2.setText(email);
Toast.makeText(getApplicationContext(), ""+email,
Toast.LENGTH_LONG).show();
}
emailCur.close();

No comments:

Post a Comment