Open your own phone book as an intention and use it to search. Possible?

Like a topic. I researched all day and I know that I know that I can add contacts using my own phone book, send SMS via sms sms application.

But I can’t find a way to use my own phone book to search for contacts. I tried working with the documentation: http://developer.android.com/reference/android/provider/ContactsContract.Intents.html#SEARCH_SUGGESTION_CLICKED

And all the common things related to this.

My question is:

Can I use my own phone book to search for contacts and get them? If so, the example is much appreciated.

+4
source share
2 answers

I found a solution to my problem thanks to my friend who linked me the same question on stackoverflow.

Basically, to get in touch with a supplier’s phone book search application, we need to start washing ourselves to begin our journey to search.

I used it inside a button that calls this method when a button is clicked.

public void showContactsChooser(final View view){ Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); startActivityForResult(intent, PICK_CONTACT); } 

Now we get a screen that shows us all the contacts that we have. We choose one and we return to our application.

To read this contact, I use this method:

  @Override 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 = getContentResolver().query(contactData, null, null, null, null); if (c.moveToFirst()){ String name = c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME)); Toast.makeText(getApplicationContext(), name, Toast.LENGTH_SHORT).show(); } } } } 

And done :)

My knowledge is taken from http://eclipsed4utoo.com/blog/android-open-contacts-activity-return-chosen-contact/ And the author of this is all right.

+3
source

If you want to find something in the phonebook, you must have READ_CONTACTS permission in your AndroidManifest.xml . There is an instruction on how to get contacts from the phone database. Get an interesting phone number and use this code to send a message by default (you do not need SEND_SMS ), but remember that the user will have to accept this message by clicking "Send"):

 Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( "sms:" + phoneNumber ) ); intent.putExtra( "sms_body", smsBody ); context.startActivity( intent ); 
+1
source

Source: https://habr.com/ru/post/1493638/


All Articles