How to add a contact in Android, for example skype, whatsapp in the application for native contacts?

I am creating a contact application, but I want to add contacts to the application to connect to the native android from my application, like Skype or WhatsApp. What class do I need to extend to implement this function?

Here is exactly what I want to create:

enter image description here

+8
java android
source share
1 answer

Well, if I understand what you are looking for. You want to use your own Android contact list. If so, follow these steps:

  • fire goal for result
  • get the intention to get the result code search result.
  • return cursor with contact information
  • set values.

A brief example. fire intent

Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,ContactsContract.CommonDataKinds.Phone.CONTENT_URI); startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT); //Receive the result public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { switch (requestCode) { case CONTACT_PICKER_RESULT: //deal with the resulting contact info. I built a separate util class for that.. but here is an example of the code. String[] projection = { ContactsContract.CommonDataKinds.Phone._ID, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Email.ADDRESS }; Uri result = data.getData(); String id = result.getLastPathSegment(); ContentResolver contentResolver = getActivity().getContentResolver(); //return cursor cur = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection, ContactsContract.CommonDataKinds.Phone._ID + " like \"" + idUser + "%\"", null, null); //Use the cursor to return what you need. } } 

Here is an example of a cursor call. Please read a few more about the contact cursor in android docs.

 email = emailCursor.getString(emailCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA)); 
-3
source share

All Articles