Puting contact number into field
Posted
by dfilkovi
on Stack Overflow
See other posts from Stack Overflow
or by dfilkovi
Published on 2010-04-05T00:25:19Z
Indexed on
2010/04/05
0:33 UTC
Read the original article
Hit count: 325
android
I have this code that has one button that let's me choose an entry from contacts, and passes that choesn contact to onActivityResult function. My question is how do I select data of that single contact when all that is passed is an Intent in data variable. That data variable, if converted to string shows something like "dat: content://contacts/people/4" so I see that selected contact is somehow passed, but what now? How to get that data?
And also all I found by googling was examples with deprecated class People, so I don't know how too use new classes.
Please help.
Thank you.
public class HelloAndroid extends Activity {
private static final int CONTACT_ACTIVITY = 100;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button contactButton = (Button) findViewById(R.id.pick_contact_button);
contactButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Uri uri = Uri.parse("content://contacts/people");
Intent contacts_intent = new Intent(Intent.ACTION_PICK, uri);
startActivityForResult(contacts_intent, CONTACT_ACTIVITY);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode){
case(CONTACT_ACTIVITY): {
if(resultCode == Activity.RESULT_OK) {
alertText(data.toString());
}
break;
}
}
}
}
© Stack Overflow or respective owner