开发者

How to get only one email id when clicked on name in contact list in android?

i want to get the only one email-id from contact list on clicking the 开发者_开发知识库contact list NAME in android. please help me. thank you


Try this :

public class PickEmailAddress extends Activity {
private static final int EMAIL_REQUEST = 0;
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void launchContacts(View v){ Intent intent=new Intent(Intent.ACTION_PICK); intent.setData(ContactsContract.CommonDataKinds.Email.CONTENT_URI); startActivityForResult(intent, EMAIL_REQUEST); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(resultCode==RESULT_OK){ switch(requestCode){ case EMAIL_REQUEST: Uri selectedUri=data.getData(); ContentResolver cr=getContentResolver(); Cursor c=cr.query(selectedUri, new String[]{ContactsContract.CommonDataKinds.Email.DATA}, null, null, null); c.moveToFirst(); String email=c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA)); Toast.makeText(this, email, Toast.LENGTH_SHORT).show(); break; } } } }

keep read contacts permission in manifest.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜