在Android中,如何选择一个联系人,并在我的应用程序显示呢? [英] In Android, how to pick a contact and display it on my app?
问题描述
我是一个初学者到Android,我建立在当用户presses一个按钮的应用程序,显示存储在手机中的联系人。当他选择从联系人,我必须得到所选择的联系人姓名和电话号码。我试着用code,但只有被选中的联系人的姓名显示,而不是电话号码。
I am a beginner to android, i am building a application in which when the user presses a button, the contacts which is stored in the mobile are shown. When he selects a contact from that, i have to get the selected contact name and number. I tried using the code but only the name of the selected contact is shown and not the phone number.
public void readcontact(){
try {
Intent intent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts/people"));
startActivityForResult(intent, PICK_CONTACT);
} catch (Exception e) {
e.printStackTrace();
}
}
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
switch (reqCode) {
case (PICK_CONTACT) :
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
startManagingCursor(c);
if (c.moveToFirst()) {
String name = c.getString(c.getColumnIndexOrThrow(People.NAME));
String number = c.getString(c.getColumnIndexOrThrow(People.NUMBER));
perrsonname.setText(name);
Toast.makeText(this, name + " has number " + number, Toast.LENGTH_LONG).show();
}
}
break;
}
}
我还需要额外的号码(家庭,办公室等,)选定的联系人, 谁能帮我出这一点。这个建议是AP preciable。
I even need the additional number(home,office etc.,)of the selected contacts, Can anyone help me out with this. Suggestions on this is appreciable.
推荐答案
请参阅联系人应用程序中附带的Android源代码
Refer Contacts Application which comes with Android Source
这篇关于在Android中,如何选择一个联系人,并在我的应用程序显示呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!