public class MsgcontactActivity extends Activity { private static final int CONTACT_PICKER_RESULT = 1001; public void doLaunchContactPicker(View view) { Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,Contacts.CONTENT_URI); startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT); } EditText phoneTxt; TextView tv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tv=(TextView) findViewById(R.id.textView1); String xx=phoneTxt.getText().toString(); Toast.makeText(getApplicationContext(), xx,Toast.LENGTH_LONG ).show(); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { { String phone=""; Cursor contacts=null; try { if (resultCode == RESULT_OK) { switch (requestCode) { case CONTACT_PICKER_RESULT: Uri result = data.getData(); String id = result.getLastPathSegment(); contacts=getContentResolver().query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + "=?", new String[] { id }, null); int phoneIdx = contacts.getColumnIndex(Phone.DATA); if (contacts.moveToFirst()) { phone = contacts.getString(phoneIdx); EditText phoneTxt=(EditText)findViewById(R.id.phoneno); phoneTxt.setText(phone); } else { Toast.makeText(this, "error", 100).show(); } break; } } else { Toast.makeText(this, "Warning: activity result not ok",50).show(); } } catch (Exception e) { Toast.makeText(this, e.getMessage(), 50).show(); } finally { if (contacts != null) { contacts.close(); } } } }