android.provider.ContactsContract Java Examples

The following examples show how to use android.provider.ContactsContract. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SharedContactRepository.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@WorkerThread
private @Nullable Name getName(long contactId) {
  try (Cursor cursor = contactsDatabase.getNameDetails(contactId)) {
    if (cursor != null && cursor.moveToFirst()) {
      String cursorDisplayName = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME));
      String cursorGivenName   = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
      String cursorFamilyName  = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
      String cursorPrefix      = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredName.PREFIX));
      String cursorSuffix      = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredName.SUFFIX));
      String cursorMiddleName  = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME));

      Name name = new Name(cursorDisplayName, cursorGivenName, cursorFamilyName, cursorPrefix, cursorSuffix, cursorMiddleName);
      if (!name.isEmpty()) {
        return name;
      }
    }
  }

  String org = contactsDatabase.getOrganizationName(contactId);
  if (!TextUtils.isEmpty(org)) {
    return new Name(org, org, null, null, null, null);
  }

  return null;
}
 
Example #2
Source File: ContactsActivity.java    From PermissMe with Apache License 2.0 6 votes vote down vote up
private ArrayList<String> getListOfContacts() {
	ArrayList<String> contactsList = new ArrayList<>();
	ContentResolver cr = getContentResolver();
	Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

	if (cur != null && cur.getCount() > 0) {
		while (cur.moveToNext()) {
			String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
			contactsList.add(name);
		}
	}
	if (contactsList.isEmpty()) {
		contactsList.add("No Contacts Found");
	}
	return contactsList;
}
 
Example #3
Source File: MainActivity.java    From AndroidDemo with MIT License 6 votes vote down vote up
private void readContacts() {
    Cursor cursor = null;
    try {
        // 查询联系人数据
        cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
        if (cursor != null) {
            while (cursor.moveToNext()) {
                // 获取联系人姓名
                String displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
                // 获取联系人手机号
                String number = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                contactsList.add(displayName + "\n" + number);
            }
            adapter.notifyDataSetChanged();
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (cursor != null) {
                cursor.close();
        }
    }
}
 
Example #4
Source File: ContactsTask.java    From SmsScheduler with GNU General Public License v2.0 6 votes vote down vote up
private HashMap<String, String> getNames() {
    HashMap<String, String> names = new HashMap<>();

    // Getting contact names
    String[] projectionPeople = new String[] {
        ContactsContract.Contacts._ID,
        ContactsContract.Contacts.DISPLAY_NAME
    };
    Cursor people = activity.getContentResolver().query(
        ContactsContract.Contacts.CONTENT_URI,
        projectionPeople,
        null,
        null,
        ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC"
    );
    if (null != people) {
        int columnIndexId = people.getColumnIndex(ContactsContract.Contacts._ID);
        int columnIndexName = people.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
        while (people.moveToNext()) {
            names.put(people.getString(columnIndexId), people.getString(columnIndexName));
        }
        people.close();
    }

    return names;
}
 
Example #5
Source File: ContactAccessorSdk5.java    From cordova-android-chromeview with Apache License 2.0 6 votes vote down vote up
/**
 * A special search that finds one contact by id
 *
 * @param id   contact to find by id
 * @return     a JSONObject representing the contact
 * @throws JSONException
 */
public JSONObject getContactById(String id) throws JSONException {
    // Do the id query
    Cursor c = mApp.getActivity().getContentResolver().query(ContactsContract.Data.CONTENT_URI,
            null,
            ContactsContract.Data.CONTACT_ID + " = ? ",
            new String[] { id },
            ContactsContract.Data.CONTACT_ID + " ASC");

    JSONArray fields = new JSONArray();
    fields.put("*");

    HashMap<String, Boolean> populate = buildPopulationSet(fields);

    JSONArray contacts = populateContactArray(1, populate, c);

    if (contacts.length() == 1) {
        return contacts.getJSONObject(0);
    } else {
        return null;
    }
}
 
Example #6
Source File: LoginActivityA.java    From ans-android-sdk with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    return new CursorLoader(this,
            // Retrieve data rows for the device user's 'profile' contact.
            Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
                    ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION,

            // Select only email addresses.
            ContactsContract.Contacts.Data.MIMETYPE +
                    " = ?", new String[]{ContactsContract.CommonDataKinds.Email
            .CONTENT_ITEM_TYPE},

            // Show primary email addresses first. Note that there won't be
            // a primary email address if the user hasn't specified one.
            ContactsContract.Contacts.Data.IS_PRIMARY + " DESC");
}
 
Example #7
Source File: ContactsDatabase.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public synchronized  void removeDeletedRawContacts(@NonNull Account account) {
  Uri currentContactsUri = RawContacts.CONTENT_URI.buildUpon()
                                                  .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name)
                                                  .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type)
                                                  .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true")
                                                  .build();

  String[] projection = new String[] {BaseColumns._ID, RawContacts.SYNC1};

  try (Cursor cursor = context.getContentResolver().query(currentContactsUri, projection, RawContacts.DELETED + " = ?", new String[] {"1"}, null)) {
    while (cursor != null && cursor.moveToNext()) {
      long rawContactId = cursor.getLong(0);
      Log.i(TAG, "Deleting raw contact: " + cursor.getString(1) + ", " + rawContactId);

      context.getContentResolver().delete(currentContactsUri, RawContacts._ID + " = ?", new String[] {String.valueOf(rawContactId)});
    }
  }
}
 
Example #8
Source File: VCardContactEncoder.java    From weex with Apache License 2.0 6 votes vote down vote up
private static String vCardPurposeLabelForAndroidType(int androidType) {
  switch (androidType) {
    case ContactsContract.CommonDataKinds.Phone.TYPE_FAX_HOME:
    case ContactsContract.CommonDataKinds.Phone.TYPE_FAX_WORK:
    case ContactsContract.CommonDataKinds.Phone.TYPE_OTHER_FAX:
      return "fax";
    case ContactsContract.CommonDataKinds.Phone.TYPE_PAGER:
    case ContactsContract.CommonDataKinds.Phone.TYPE_WORK_PAGER:
      return "pager";
    case ContactsContract.CommonDataKinds.Phone.TYPE_TTY_TDD:
      return "textphone";
    case ContactsContract.CommonDataKinds.Phone.TYPE_MMS:
      return "text";
    default:
      return null;
  }
}
 
Example #9
Source File: VCardContactEncoder.java    From ZXing-Standalone-library with Apache License 2.0 6 votes vote down vote up
private static String vCardPurposeLabelForAndroidType(int androidType) {
  switch (androidType) {
    case ContactsContract.CommonDataKinds.Phone.TYPE_FAX_HOME:
    case ContactsContract.CommonDataKinds.Phone.TYPE_FAX_WORK:
    case ContactsContract.CommonDataKinds.Phone.TYPE_OTHER_FAX:
      return "fax";
    case ContactsContract.CommonDataKinds.Phone.TYPE_PAGER:
    case ContactsContract.CommonDataKinds.Phone.TYPE_WORK_PAGER:
      return "pager";
    case ContactsContract.CommonDataKinds.Phone.TYPE_TTY_TDD:
      return "textphone";
    case ContactsContract.CommonDataKinds.Phone.TYPE_MMS:
      return "text";
    default:
      return null;
  }
}
 
Example #10
Source File: ContactAccessorSdk5.java    From showCaseCordova with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a string from the W3C Contact API to it's Android int value.
 * @param string
 * @return Android int value
 */
private int getContactType(String string) {
    int type = ContactsContract.CommonDataKinds.Email.TYPE_OTHER;
    if (string != null) {
        if ("home".equals(string.toLowerCase())) {
            return ContactsContract.CommonDataKinds.Email.TYPE_HOME;
        }
        else if ("work".equals(string.toLowerCase())) {
            return ContactsContract.CommonDataKinds.Email.TYPE_WORK;
        }
        else if ("other".equals(string.toLowerCase())) {
            return ContactsContract.CommonDataKinds.Email.TYPE_OTHER;
        }
        else if ("mobile".equals(string.toLowerCase())) {
            return ContactsContract.CommonDataKinds.Email.TYPE_MOBILE;
        }
        else if ("custom".equals(string.toLowerCase())) {
            return ContactsContract.CommonDataKinds.Email.TYPE_CUSTOM;
        }
    }
    return type;
}
 
Example #11
Source File: ContactsView.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main);
	TextView contactView = (TextView) findViewById(R.id.contactview);

	Cursor cursor = getContacts();

	while (cursor.moveToNext()) {

		String displayName = cursor.getString(cursor
				.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
		contactView.append("Name: ");
		contactView.append(displayName);
		contactView.append("\n");
	}
	// Closing the cursor
	cursor.close();
}
 
Example #12
Source File: ContactPickerActivity.java    From Android-ContactPicker with Apache License 2.0 6 votes vote down vote up
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    String selection = "";
    if(mOnlyWithPhoneNumbers){
        selection = ContactsContract.Contacts.HAS_PHONE_NUMBER;
    }
    switch(id) {
        case CONTACTS_LOADER_ID:
            return new CursorLoader(this, CONTACTS_URI, CONTACTS_PROJECTION,
                    selection, null, CONTACTS_SORT);
        case CONTACT_DETAILS_LOADER_ID:
            return new CursorLoader(this, CONTACT_DETAILS_URI, CONTACT_DETAILS_PROJECTION,
                    selection, null, null);
        case GROUPS_LOADER_ID:
            return new CursorLoader(this, GROUPS_URI, GROUPS_PROJECTION, GROUPS_SELECTION, null, GROUPS_SORT);
    }
    return null;
}
 
Example #13
Source File: ContactAccessorSdk5.java    From jpHolo with MIT License 6 votes vote down vote up
/**
 * getPhoneType converts an Android phone type into a string
 * @param type
 * @return phone type as string.
 */
private String getOrgType(int type) {
    String stringType;
    switch (type) {
    case ContactsContract.CommonDataKinds.Organization.TYPE_CUSTOM:
        stringType = "custom";
        break;
    case ContactsContract.CommonDataKinds.Organization.TYPE_WORK:
        stringType = "work";
        break;
    case ContactsContract.CommonDataKinds.Organization.TYPE_OTHER:
    default:
        stringType = "other";
        break;
    }
    return stringType;
}
 
Example #14
Source File: EspContactTool.java    From espresso-macchiato with MIT License 6 votes vote down vote up
public static Uri addressUriByDisplayName(String contactName) {
    Uri result = null;
    Cursor cursor = InstrumentationRegistry.getTargetContext().getContentResolver().query(
            ContactsContract.Data.CONTENT_URI,
            null,
            ContactsContract.Data.MIMETYPE + " = ? ",
            new String[]{ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE},
            null);

    assertNotNull(cursor);
    if (cursor.getCount() > 0) {
        while (cursor.moveToNext()) {
            String id = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal._ID));
            String name = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.DISPLAY_NAME));
            if (contactName.equals(name)) {
                result = Uri.withAppendedPath(ContactsContract.Data.CONTENT_URI, id);
                break;
            }
        }
    }

    cursor.close();
    return result;
}
 
Example #15
Source File: ContactAccessorSdk5.java    From showCaseCordova with Apache License 2.0 6 votes vote down vote up
/**
 * getPhoneType converts an Android phone type into a string
 * @param type
 * @return phone type as string.
 */
private String getAddressType(int type) {
    String stringType;
    switch (type) {
    case ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME:
        stringType = "home";
        break;
    case ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK:
        stringType = "work";
        break;
    case ContactsContract.CommonDataKinds.StructuredPostal.TYPE_OTHER:
    default:
        stringType = "other";
        break;
    }
    return stringType;
}
 
Example #16
Source File: MainActivity.java    From Finder with GNU General Public License v3.0 6 votes vote down vote up
protected void onActivityResult(int requestCode, int resultCode,
                                Intent data) {
    if (requestCode == REQUEST_CODE_CONTACTS) {
        if (resultCode == RESULT_OK) {
            Uri uri = data.getData();
            String[] columns_to_get = new String[] {ContactsContract.CommonDataKinds.Phone.NUMBER,
                                                    ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME};
            Cursor curs = getContentResolver().query(uri, columns_to_get, null, null, null);

            if (curs != null && curs.moveToFirst()) {
                String name = curs.getString(1);
                String number = curs.getString(0);
                field_name.setText(name);
                field_phone.setText(number.replaceAll("\\s+|-+|[()]+", ""));
            }
        }
    }
}
 
Example #17
Source File: ContactAccessorSdk5.java    From showCaseCordova with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a string from the W3C Contact API to it's Android int value.
 * @param string
 * @return Android int value
 */
private int getAddressType(String string) {
    int type = ContactsContract.CommonDataKinds.StructuredPostal.TYPE_OTHER;
    if (string != null) {
        if ("work".equals(string.toLowerCase())) {
            return ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK;
        }
        else if ("other".equals(string.toLowerCase())) {
            return ContactsContract.CommonDataKinds.StructuredPostal.TYPE_OTHER;
        }
        else if ("home".equals(string.toLowerCase())) {
            return ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME;
        }
    }
    return type;
}
 
Example #18
Source File: VCardContactEncoder.java    From ZXing-Orient with Apache License 2.0 6 votes vote down vote up
private static String vCardContextLabelForAndroidType(int androidType) {
  switch (androidType) {
    case ContactsContract.CommonDataKinds.Phone.TYPE_HOME:
    case ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE:
    case ContactsContract.CommonDataKinds.Phone.TYPE_FAX_HOME:
    case ContactsContract.CommonDataKinds.Phone.TYPE_PAGER:
      return "home";
    case ContactsContract.CommonDataKinds.Phone.TYPE_COMPANY_MAIN:
    case ContactsContract.CommonDataKinds.Phone.TYPE_WORK:
    case ContactsContract.CommonDataKinds.Phone.TYPE_WORK_MOBILE:
    case ContactsContract.CommonDataKinds.Phone.TYPE_FAX_WORK:
    case ContactsContract.CommonDataKinds.Phone.TYPE_WORK_PAGER:
      return "work";
    default:
      return null;
  }
}
 
Example #19
Source File: DeleteContactsCommand.java    From mobilecloud-15 with Apache License 2.0 5 votes vote down vote up
/**
 * Delete the contact with the designated @a name.
 */
private int deleteContact(String name) {
    return mContentResolver.delete(ContactsContract.RawContacts.CONTENT_URI,
                                   ContactsContract.Contacts.DISPLAY_NAME
                                   + "=?",
                                   new String[] { name });
}
 
Example #20
Source File: ContactsProvider.java    From sealtalk-android with MIT License 5 votes vote down vote up
/**
 * click 事件
 *
 * @param view
 */
@Override
public void onPluginClick(View view) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_PICK);
    intent.setData(ContactsContract.Contacts.CONTENT_URI);
    startActivityForResult(intent, REQUEST_CONTACT);
}
 
Example #21
Source File: ColumnMapper.java    From MultiContactPicker with Apache License 2.0 5 votes vote down vote up
static void mapPhoneNumber (Context con, Cursor cursor, Contact contact, int noColumnIndex, int typeColIndex, int labelColIndex) {
    String phoneNumber = cursor.getString(noColumnIndex);
    int phonetype = cursor.getInt(typeColIndex);
    String customLabel = cursor.getString(labelColIndex);
    String phoneLabel = (String) ContactsContract.CommonDataKinds.Phone.getTypeLabel(con.getResources(), phonetype, customLabel);
    if (phoneNumber != null && !phoneNumber.isEmpty()) {
        // Remove all whitespaces
        phoneNumber = phoneNumber.replaceAll("\\s+","");
        contact.getPhoneNumbers().add(new PhoneNumber(phoneLabel, phoneNumber.trim()));
    }
}
 
Example #22
Source File: ContactHelper.java    From NotificationPeekPort with Apache License 2.0 5 votes vote down vote up
/**
 * Get the InputStream object of the contact photo with given contact ID.
 *
 * @param context       Context object of the caller.
 * @param contactId     Contact ID.
 * @return              InputStream object of the contact photo.
 */
public static InputStream openDisplayPhoto(Context context, long contactId) {
    Uri contactUri =
            ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId);
    Uri displayPhotoUri =
            Uri.withAppendedPath(contactUri, ContactsContract.Contacts.Photo.DISPLAY_PHOTO);
    try {
        AssetFileDescriptor fd =
                context.getContentResolver().openAssetFileDescriptor(displayPhotoUri, "r");
        return fd.createInputStream();
    } catch (IOException e) {
        return null;
    }
}
 
Example #23
Source File: EmergencyAssistActivity.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public void chooseContact(View v) {
    if (checkContactsPermission()) {
        try {
            final Intent intent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts"));
            intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
            startActivityForResult(intent, CONTACT_REQUEST_CODE);
        } catch (ActivityNotFoundException e) {
            JoH.static_toast_long("Device doesn't have a contact picker!?");
        }
    }
}
 
Example #24
Source File: LinphoneContact.java    From linphone-android with GNU General Public License v3.0 5 votes vote down vote up
private synchronized void syncValuesFromAndroidContact(Context context) {
    Cursor c = null;
    try {
        c =
                context.getContentResolver()
                        .query(
                                ContactsContract.Data.CONTENT_URI,
                                AsyncContactsLoader.PROJECTION,
                                ContactsContract.Data.IN_DEFAULT_DIRECTORY
                                        + " == 1 AND "
                                        + ContactsContract.Data.CONTACT_ID
                                        + " == "
                                        + mAndroidId,
                                null,
                                null);
    } catch (SecurityException se) {
        Log.e("[Contact] Security exception: ", se);
    }

    if (c != null) {
        mAddresses = new ArrayList<>();
        while (c.moveToNext()) {
            syncValuesFromAndroidCusor(c);
        }
        c.close();
    }
}
 
Example #25
Source File: ContactHelper.java    From android-auto-call-recorder with MIT License 5 votes vote down vote up
public boolean insertContact(ContentResolver contactAdder, String firstName, String mobileNumber) {
    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
    ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI).withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null).withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null).build());
    ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0).withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE).withValue(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, firstName).build());
    ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0).withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE).withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, mobileNumber).withValue(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE).build());
    try {
        contactAdder.applyBatch(ContactsContract.AUTHORITY, ops);
    } catch (Exception e) {
        return false;
    }
    return true;
}
 
Example #26
Source File: LinphoneContact.java    From Linphone4Android with GNU General Public License v3.0 5 votes vote down vote up
private String findRawContactID() {
	ContentResolver resolver = ContactsManager.getInstance().getContentResolver();
	String result = null;
	String[] projection = { ContactsContract.RawContacts._ID };

	String selection = ContactsContract.RawContacts.CONTACT_ID + "=?";
	Cursor c = resolver.query(ContactsContract.RawContacts.CONTENT_URI, projection, selection, new String[]{ getAndroidId() }, null);
	if (c != null) {
		if (c.moveToFirst()) {
			result = c.getString(c.getColumnIndex(ContactsContract.RawContacts._ID));
		}
		c.close();
	}
	return result;
}
 
Example #27
Source File: ContactsController.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
protected void markAsContacted(final String contactId) {
    if (contactId == null) {
        return;
    }
    Utilities.phoneBookQueue.postRunnable(() -> {
        Uri uri = Uri.parse(contactId);
        ContentValues values = new ContentValues();
        values.put(ContactsContract.Contacts.LAST_TIME_CONTACTED, System.currentTimeMillis());
        ContentResolver cr = ApplicationLoader.applicationContext.getContentResolver();
        cr.update(uri, values, null, null);
    });
}
 
Example #28
Source File: LinphoneContact.java    From Linphone4Android with GNU General Public License v3.0 5 votes vote down vote up
private void getNativeContactOrganization() {
	ContentResolver resolver = ContactsManager.getInstance().getContentResolver();
	String[] proj = new String[]{ CommonDataKinds.Organization.COMPANY };
	String select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "=?";
	String[] args = new String[]{ getAndroidId(), CommonDataKinds.Organization.CONTENT_ITEM_TYPE };
	Cursor c = resolver.query(ContactsContract.Data.CONTENT_URI, proj, select, args, null);
	if (c != null) {
		if (c.moveToFirst()) {
			organization = c.getString(c.getColumnIndex(CommonDataKinds.Organization.COMPANY));
		}
		c.close();
	}
}
 
Example #29
Source File: EspContactToolTest.java    From espresso-macchiato with MIT License 5 votes vote down vote up
protected int queryContactCount() {
    Cursor cursor = InstrumentationRegistry.getContext().getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, null, null, null);
    assertNotNull(cursor);
    int count = cursor.getCount();
    cursor.close();
    return count;
}
 
Example #30
Source File: ContactsServicePlugin.java    From flutter_contacts with MIT License 5 votes vote down vote up
private boolean deleteContact(Contact contact){
  ArrayList<ContentProviderOperation> ops = new ArrayList<>();
  ops.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI)
          .withSelection(ContactsContract.RawContacts.CONTACT_ID + "=?", new String[]{String.valueOf(contact.identifier)})
          .build());
  try {
    contentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
    return true;
  } catch (Exception e) {
    return false;

  }
}