How can I use a button to retrieve a phone 'number' from contacts?

Use Button to Open Contacts to Retrieve Phone Number and Print to String

  • So I do some android development on and off, and right now I'm a bit rusty. Basically all I want to do is have the user press a button and then that brings them to choose a contact, and then that prints that to a string. I have onCick running as such @Override public void onClick(View paramView) { Main.this.phone = Main.this with other things attached to it. So how would I load contacts as I expect to. I can provide more information as needed.

  • Answer:

    The pattern should be: onClick() { intent = new Intent(Intent.ACTION_PICK); intent.setData(null); intent.setType(null); startActivityForResult(intent,0); } onActivityResult(int requestcode, int resultcode, Intent returnIntent) { Uri resultUri = returnIntent.getData(); } The intent you send out will cause the contacts app to display a picker, from which the user can choose a contact. The content URI of that contact is returned to you in onActivityResult(), in another intent. You can use that to look for data for that particular contact.

sipjca at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.