Java Code Examples for android.provider.ContactsContract

The following examples show how to use android.provider.ContactsContract. These examples are extracted from open source projects. 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
@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 2
Source Project: espresso-macchiato   Source File: EspContactTool.java    License: 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 3
Source Project: PermissMe   Source File: ContactsActivity.java    License: 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 4
Source Project: AndroidDemo   Source File: MainActivity.java    License: 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 5
Source Project: SmsScheduler   Source File: ContactsTask.java    License: 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 6
/**
 * 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 7
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 Project: weex   Source File: VCardContactEncoder.java    License: 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
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 Project: jpHolo   Source File: ContactAccessorSdk5.java    License: 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 11
Source Project: ZXing-Orient   Source File: VCardContactEncoder.java    License: 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 12
Source Project: Finder   Source File: MainActivity.java    License: 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 13
@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 14
Source Project: showCaseCordova   Source File: ContactAccessorSdk5.java    License: 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 15
Source Project: showCaseCordova   Source File: ContactAccessorSdk5.java    License: 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
@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 17
Source Project: codeexamples-android   Source File: ContactsView.java    License: 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 18
Source Project: showCaseCordova   Source File: ContactAccessorSdk5.java    License: 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 19
Source Project: repay-android   Source File: ContactsContractHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get the main email address of the contact
 * @param contactID The last known ContactID of the contact
 * @param c The context to run in
 * @return String representation of their email address
 * @throws android.database.CursorIndexOutOfBoundsException
 */
public static HashMap<String,String> getContactsEmailAddress(String contactID, Context c) throws CursorIndexOutOfBoundsException
{
	/*
	 * For some shitting reason, using ContactsContract.CommonDataKinds.Phone works instead of Email?
	 * Leaving it anyway, might just be some stupid HTC Sense 5 bug
	 */
	HashMap<String,String> emails = new HashMap<String,String>();
	for(int i=0;i<=typesEmail.length-1;i++){
		String[] whereArgs = new String[] {String.valueOf(contactID), String.valueOf(typesEmail[i])};
		String email = queryContactForEmail(c, whereArgs);
		if(email!=null){
			if(ContactsContract.CommonDataKinds.Phone.TYPE_HOME==typesEmail[i]){
				emails.put("Home", email);
			}
			else if(ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE==typesEmail[i]){
				emails.put("Other", email);
			}
			else if(ContactsContract.CommonDataKinds.Phone.TYPE_WORK==typesEmail[i]){
				emails.put("Work", email);
			}
		}
	}
	return emails;
}
 
Example 20
Source Project: candybar   Source File: BaseImageDownloader.java    License: Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
protected InputStream getContactPhotoStream(Uri uri) {
    ContentResolver res = context.getContentResolver();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        return ContactsContract.Contacts.openContactPhotoInputStream(res, uri, true);
    } else {
        return ContactsContract.Contacts.openContactPhotoInputStream(res, uri);
    }
}
 
Example 21
/**
 * Create a ContactName JSONObject
 * @param cursor the current database row
 * @return a JSONObject representing a ContactName
 */
private JSONObject nameQuery(Cursor cursor) {
    JSONObject contactName = new JSONObject();
    try {
        String familyName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
        String givenName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
        String middleName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME));
        String honorificPrefix = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.PREFIX));
        String honorificSuffix = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.SUFFIX));

        // Create the formatted name
        StringBuffer formatted = new StringBuffer("");
        if (honorificPrefix != null) {
            formatted.append(honorificPrefix + " ");
        }
        if (givenName != null) {
            formatted.append(givenName + " ");
        }
        if (middleName != null) {
            formatted.append(middleName + " ");
        }
        if (familyName != null) {
            formatted.append(familyName);
        }
        if (honorificSuffix != null) {
            formatted.append(" " + honorificSuffix);
        }

        contactName.put("familyName", familyName);
        contactName.put("givenName", givenName);
        contactName.put("middleName", middleName);
        contactName.put("honorificPrefix", honorificPrefix);
        contactName.put("honorificSuffix", honorificSuffix);
        contactName.put("formatted", formatted);
    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
    }
    return contactName;
}
 
Example 22
private Cursor getGroupsCursor() {
  MatrixCursor groupContacts = new MatrixCursor(CONTACT_PROJECTION);
  try (GroupDatabase.Reader reader = DatabaseFactory.getGroupDatabase(getContext()).getGroupsFilteredByTitle(filter, flagSet(mode, DisplayMode.FLAG_INACTIVE_GROUPS))) {
    GroupDatabase.GroupRecord groupRecord;
    while ((groupRecord = reader.getNext()) != null) {
      groupContacts.addRow(new Object[] { groupRecord.getRecipientId().serialize(),
                                          groupRecord.getTitle(),
                                          groupRecord.getId(),
                                          ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM,
                                          "",
                                          ContactRepository.NORMAL_TYPE });
    }
  }
  return groupContacts;
}
 
Example 23
private Cursor getNewNumberCursor() {
  MatrixCursor newNumberCursor = new MatrixCursor(CONTACT_PROJECTION, 1);
  newNumberCursor.addRow(new Object[] { null,
                                        getUnknownContactTitle(),
                                        filter,
                                        ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM,
                                        "\u21e2",
                                        ContactRepository.NEW_PHONE_TYPE});
  return newNumberCursor;
}
 
Example 24
Source Project: react-native-paged-contacts   Source File: Organization.java    License: MIT License 5 votes vote down vote up
@Override
public void addCreationOp(ArrayList<ContentProviderOperation> ops) {
    ContentProviderOperation.Builder op = 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.Organization.COMPANY, organizationName)
            .withValue(ContactsContract.CommonDataKinds.Organization.DEPARTMENT, departmentName)
            .withValue(ContactsContract.CommonDataKinds.Organization.TITLE, jobTitle)
            .withValue(ContactsContract.CommonDataKinds.Organization.PHONETIC_NAME, phoneticOrganizationName);

    ops.add(op.build());
}
 
Example 25
Source Project: mobilecloud-15   Source File: ContactsOpsImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Register the ContentObserver.
 */
protected void registerContentObserver() {
    // Register a ContentObserver that's notified when Contacts
    // change (e.g., are inserted, modified, or deleted).
    getActivityContext().getContentResolver().registerContentObserver
        (ContactsContract.Contacts.CONTENT_URI,
         true,
         contactsChangeContentObserver);
}
 
Example 26
Source Project: react-native-contacts   Source File: ContactsProvider.java    License: MIT License 5 votes vote down vote up
public WritableArray getContactsByPhoneNumber(String phoneNumber) {
    Map<String, Contact> matchingContacts;
    {
        Cursor cursor = contentResolver.query(
                ContactsContract.Data.CONTENT_URI,
                FULL_PROJECTION.toArray(new String[FULL_PROJECTION.size()]),
                ContactsContract.CommonDataKinds.Phone.NUMBER + " LIKE ? OR "
                        + ContactsContract.CommonDataKinds.Phone.NORMALIZED_NUMBER + " LIKE ?",
                new String[]{"%" + phoneNumber + "%", "%" + phoneNumber + "%"},
                null
        );

        try {
            matchingContacts = loadContactsFrom(cursor);
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }

    WritableArray contacts = Arguments.createArray();
    for (Contact contact : matchingContacts.values()) {
        contacts.pushMap(contact.toMap());
    }
    return contacts;
}
 
Example 27
public ContactOperations(Context context, String accountName, String accountType) {
	this.context = context;

	account = new NonEmptyContentValues();
	account.put(ContactsContract.RawContacts.ACCOUNT_TYPE, accountType);
	account.put(ContactsContract.RawContacts.ACCOUNT_NAME, accountName);
}
 
Example 28
Source Project: showCaseCordova   Source File: ContactAccessorSdk5.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a ContactField JSONObject
 * @param cursor the current database row
 * @return a JSONObject representing a ContactField
 */
private JSONObject websiteQuery(Cursor cursor) {
    JSONObject website = new JSONObject();
    try {
        website.put("id", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Website._ID)));
        website.put("pref", false); // Android does not store pref attribute
        website.put("value", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Website.URL)));
        website.put("type", getContactType(cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Website.TYPE))));
    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
    }
    return website;
}
 
Example 29
private static Optional<AccountHolder> getOrCreateAccount(Context context) {
  AccountManager accountManager = AccountManager.get(context);
  Account[]      accounts       = accountManager.getAccountsByType(context.getPackageName());

  Optional<AccountHolder> account;

  if (accounts.length == 0) account = createAccount(context);
  else                      account = Optional.of(new AccountHolder(accounts[0], false));

  if (account.isPresent() && !ContentResolver.getSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY)) {
    ContentResolver.setSyncAutomatically(account.get().getAccount(), ContactsContract.AUTHORITY, true);
  }

  return account;
}
 
Example 30
Source Project: Identiconizer   Source File: ContactsListActivity.java    License: Apache License 2.0 5 votes vote down vote up
private Cursor getContacts() {
    Uri uri = ContactsContract.Contacts.CONTENT_URI;
    String[] projection = new String[]{
            ContactsContract.Contacts._ID,
            "name_raw_contact_id",
            ContactsContract.Contacts.DISPLAY_NAME,
            ContactsContract.Contacts.PHOTO_THUMBNAIL_URI
    };
    String selection = "in_visible_group = '1'";
    if (Config.getInstance(this).shouldIgnoreContactVisibility())
        selection = null;
    String sortOrder = "display_name COLLATE LOCALIZED ASC";

    return getContentResolver().query(uri, projection, selection, null, sortOrder);
}