Java 类android.provider.ContactsContract.Data 实例源码

项目:Linphone4Android    文件:ContactsManager.java   
public void deleteMultipleContactsAtOnce(List<String> ids) {
    String select = Data.CONTACT_ID + " = ?";
    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

    for (String id : ids) {
        String[] args = new String[] { id };
        ops.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI).withSelection(select, args).build());
    }

    ContentResolver cr = ContactsManager.getInstance().getContentResolver();
    try {
        cr.applyBatch(ContactsContract.AUTHORITY, ops);
    } catch (Exception e) {
        Log.e(e);
    }
}
项目:CSipSimple    文件:ContactsUtils5.java   
@Override
public Intent getAddContactIntent(String displayName, String csipUri) {
    Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT, Contacts.CONTENT_URI);
    intent.setType(Contacts.CONTENT_ITEM_TYPE);

    if (!TextUtils.isEmpty(displayName)) {
        intent.putExtra(Insert.NAME, displayName);
    }

    if (!TextUtils.isEmpty(csipUri)) {
        ArrayList<ContentValues> data = new ArrayList<ContentValues>();
        ContentValues csipProto = new ContentValues();
        csipProto.put(Data.MIMETYPE, CommonDataKinds.Im.CONTENT_ITEM_TYPE);
        csipProto.put(CommonDataKinds.Im.PROTOCOL, CommonDataKinds.Im.PROTOCOL_CUSTOM);
        csipProto.put(CommonDataKinds.Im.CUSTOM_PROTOCOL, SipManager.PROTOCOL_CSIP);
        csipProto.put(CommonDataKinds.Im.DATA, SipUri.getCanonicalSipContact(csipUri, false));
        data.add(csipProto);

        intent.putParcelableArrayListExtra(Insert.DATA, data);
    }

    return intent;
}
项目:NoticeDog    文件:WhatsAppApp.java   
String getWhatsAppNumber(String name) {
    Cursor cursor = this.context.getContentResolver().query(Data.CONTENT_URI, new String[]{"data3"}, "display_name=? AND mimetype=?", new String[]{name, WHATSAPP_CONTACT_MIMETYPE}, null);
    String phoneNumber = null;
    int foundContacts = 0;
    while (cursor.moveToNext()) {
        foundContacts++;
        if (foundContacts > 1) {
            Log.d(TAG, "Found more than one WhatsApp contact -- skipping WhatsApp deeplinking");
            phoneNumber = null;
            break;
        }
        phoneNumber = cursor.getString(cursor.getColumnIndex("data3"));
        Log.d(TAG, "Found WhatsApp # " + phoneNumber + " for " + name);
    }
    cursor.close();
    return phoneNumber;
}
项目:TextSecure    文件:ContactAccessor.java   
public List<ContactData> getGroupMembership(Context context, long groupId) {
  LinkedList<ContactData> contacts = new LinkedList<ContactData>();
  Cursor groupMembership           = null;

  try {
    String selection = ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID + " = ? AND " +
                       ContactsContract.CommonDataKinds.GroupMembership.MIMETYPE + " = ?";
    String[] args    = new String[] {groupId+"",
                                     ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE};

    groupMembership = context.getContentResolver().query(Data.CONTENT_URI, null, selection, args, null);

    while (groupMembership != null && groupMembership.moveToNext()) {
      String displayName = groupMembership.getString(groupMembership.getColumnIndexOrThrow(Data.DISPLAY_NAME));
      long contactId     = groupMembership.getLong(groupMembership.getColumnIndexOrThrow(Data.CONTACT_ID));

      contacts.add(getContactData(context, displayName, contactId));
    }
  } finally {
    if (groupMembership != null)
      groupMembership.close();
  }

  return contacts;
}
项目:Madad_SOS    文件:ContactItemFragment.java   
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    // Choose the proper action
    switch (id) {
        case DETAILS_QUERY_ID:
            // Assigns the selection parameter
            mSelectionArgs[0] = mLookupKey;
            Log.i("Info","Key"+mLookupKey);
            // Starts the query
            CursorLoader mLoader =
                    new CursorLoader(
                            getActivity(),
                            Data.CONTENT_URI,
                            PROJECTION,
                            SELECTION,
                            mSelectionArgs,
                            SORT_ORDER
                    );
            return mLoader;
    }
    return null;
}
项目:phoneContact    文件:ContactDAO.java   
/**
 * ������ϵ��ID��ȡ��ϵ������Ⱥ��
 * 
 * @param contactId
 *            ��ϵ��ID
 * @return
 */
public int getGroupIdByContactId(int contactId) {
    Uri uri = ContactsContract.Data.CONTENT_URI;

    String[] RAW_PROJECTION = new String[] { Data.MIMETYPE, Data.DATA1 };
    Cursor cursor = context.getContentResolver().query(uri, RAW_PROJECTION,
            Data.RAW_CONTACT_ID + "=?", new String[] { contactId + "" },
            null);
    int groupId = 0;
    while (cursor.moveToNext()) {
        String mime = cursor.getString(cursor.getColumnIndex("mimetype"));

        if ("vnd.android.cursor.item/group_membership".equals(mime)) {
            groupId = cursor.getInt(cursor.getColumnIndex("data1"));
        }
    }
    cursor.close();
    return groupId;
}
项目:TextSecureSMP    文件:ContactAccessor.java   
public List<ContactData> getGroupMembership(Context context, long groupId) {
  LinkedList<ContactData> contacts = new LinkedList<ContactData>();
  Cursor groupMembership           = null;

  try {
    String selection = ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID + " = ? AND " +
                       ContactsContract.CommonDataKinds.GroupMembership.MIMETYPE + " = ?";
    String[] args    = new String[] {groupId+"",
                                     ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE};

    groupMembership = context.getContentResolver().query(Data.CONTENT_URI, null, selection, args, null);

    while (groupMembership != null && groupMembership.moveToNext()) {
      String displayName = groupMembership.getString(groupMembership.getColumnIndexOrThrow(Data.DISPLAY_NAME));
      long contactId     = groupMembership.getLong(groupMembership.getColumnIndexOrThrow(Data.CONTACT_ID));

      contacts.add(getContactData(context, displayName, contactId));
    }
  } finally {
    if (groupMembership != null)
      groupMembership.close();
  }

  return contacts;
}
项目:SDC    文件:ContactsListFragment.java   
@Override
protected Void doInBackground(Long... ids) {
    String[] projection = new String[] {Phone.DISPLAY_NAME, Phone.TYPE, Phone.NUMBER, Phone.LABEL};
    long contactId = ids[0];

    final Cursor phoneCursor = getActivity().getContentResolver().query(
            Phone.CONTENT_URI,
            projection,
            Data.CONTACT_ID + "=?",
            new String[]{String.valueOf(contactId)},
            null);

    if(phoneCursor != null && phoneCursor.moveToFirst() && phoneCursor.getCount() == 1) {
        final int contactNumberColumnIndex  = phoneCursor.getColumnIndex(Phone.NUMBER);
        mPhoneNumber = phoneCursor.getString(contactNumberColumnIndex);
        int type = phoneCursor.getInt(phoneCursor.getColumnIndexOrThrow(Phone.TYPE));
        mPhoneLabel = phoneCursor.getString(phoneCursor.getColumnIndex(Phone.LABEL));
        mPhoneLabel = Phone.getTypeLabel(getResources(), type, mPhoneLabel).toString();
        phoneCursor.close();
    }

    return null;
}
项目:mc_backup    文件:ContactService.java   
private ContentValues createAddressContentValues(final JSONObject address, final int typeConstant,
                                                 final String type) throws JSONException {
    ContentValues contentValues = new ContentValues();
    contentValues.put(Data.MIMETYPE, StructuredPostal.CONTENT_ITEM_TYPE);
    contentValues.put(StructuredPostal.STREET, address.optString("streetAddress"));
    contentValues.put(StructuredPostal.CITY, address.optString("locality"));
    contentValues.put(StructuredPostal.REGION, address.optString("region"));
    contentValues.put(StructuredPostal.POSTCODE, address.optString("postalCode"));
    contentValues.put(StructuredPostal.COUNTRY, address.optString("countryName"));

    if (type != null) {
        contentValues.put(StructuredPostal.TYPE, typeConstant);

        // If a custom type, add a label
        if (typeConstant == BaseTypes.TYPE_CUSTOM) {
            contentValues.put(StructuredPostal.LABEL, type);
        }
    }

    if (address.has("pref")) {
        contentValues.put(Data.IS_SUPER_PRIMARY, address.getBoolean("pref") ? 1 : 0);
    }

    return contentValues;
}
项目:mc_backup    文件:ContactService.java   
private ContentValues createContentValues(final String mimeType, final String value, final int typeConstant,
                                          final String type, final boolean preferredValue) {
    ContentValues contentValues = new ContentValues();
    contentValues.put(Data.MIMETYPE, mimeType);
    contentValues.put(Data.DATA1, value);
    contentValues.put(Data.IS_SUPER_PRIMARY, preferredValue ? 1 : 0);

    if (type != null) {
        contentValues.put(Data.DATA2, typeConstant);

        // If a custom type, add a label
        if (typeConstant == BaseTypes.TYPE_CUSTOM) {
            contentValues.put(Data.DATA3, type);
        }
    }

    return contentValues;
}
项目:mobilecloud-15    文件:InsertContactsCommand.java   
/**
 * Synchronously insert a contact with the designated @name into
 * the ContactsContentProvider.  This code is explained at
 * http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.html.
 */
private void addContact(String name,
                        List<ContentProviderOperation> cpops) {
    final int position = cpops.size();

    // First part of operation.
    cpops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
              .withValue(RawContacts.ACCOUNT_TYPE,
                         mOps.getAccountType())
              .withValue(RawContacts.ACCOUNT_NAME,
                         mOps.getAccountName())
              .withValue(Contacts.STARRED,
                         1)
              .build());

    // Second part of operation.
    cpops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
              .withValueBackReference(Data.RAW_CONTACT_ID,
                                      position)
              .withValue(Data.MIMETYPE,
                         StructuredName.CONTENT_ITEM_TYPE)
              .withValue(StructuredName.DISPLAY_NAME,
                         name)
              .build());
}
项目:mobilecloud-15    文件:InsertContactsCommand.java   
/**
 * Synchronously insert a contact with the designated @name into
 * the ContactsContentProvider.  This code is explained at
 * http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.html.
 */
private void addContact(String name,
                        List<ContentProviderOperation> cpops) {
    final int position = cpops.size();

    // First part of operation.
    cpops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
              .withValue(RawContacts.ACCOUNT_TYPE,
                         mOps.getAccountType())
              .withValue(RawContacts.ACCOUNT_NAME,
                         mOps.getAccountName())
              .withValue(Contacts.STARRED,
                         1)
              .build());

    // Second part of operation.
    cpops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
              .withValueBackReference(Data.RAW_CONTACT_ID,
                                      position)
              .withValue(Data.MIMETYPE,
                         StructuredName.CONTENT_ITEM_TYPE)
              .withValue(StructuredName.DISPLAY_NAME,
                         name)
              .build());
}
项目:android-authenticator    文件:ContactManager.java   
/**
 * Returns the Data id for a sample SyncAdapter contact's profile row, or 0
 * if the sample SyncAdapter user isn't found.
 *
 * @param resolver a content resolver
 * @param userId   the sample SyncAdapter user ID to lookup
 * @return the profile Data row id, or 0 if not found
 */
private static long lookupProfile(ContentResolver resolver, String userId) {

    long profileId = 0;
    final Cursor c =
            resolver.query(Data.CONTENT_URI, ProfileQuery.PROJECTION, ProfileQuery.SELECTION,
                    new String[]{String.valueOf(userId)}, null);
    try {
        if ((c != null) && c.moveToFirst()) {
            profileId = c.getLong(ProfileQuery.COLUMN_ID);
        }
    } finally {
        if (c != null) {
            c.close();
        }
    }
    return profileId;
}
项目:HtcOneTweaker    文件:TweakerBroadcastReceiver.java   
public void getPhoneNumbers(String id)
{
    Log.d("getPhoneNumbers", "looking data for contact id: " + id);
    Cursor pCur = mContext.getContentResolver().query(Data.CONTENT_URI, new String[]
    { Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL }, Data.CONTACT_ID + "=?" + " AND "
               + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'", new String[]
    { String.valueOf(id) }, null);

    while (pCur.moveToNext())
    {
        String phoneNumber = pCur.getString(1);
        String phoneType = pCur.getString(2);
        String phoneLabel = pCur.getString(3);

        if (isNumeric(phoneType))
        {
            Log.d("getPhoneNumbers", "phoneNumber: " + phoneNumber + ", phoneType: " + phoneType + ", phoneLabel: " + phoneLabel);
        }
    }
    pCur.close();
    return;
}
项目:androidclient    文件:Syncer.java   
private void addContactData(String username, String phone, List<ContentProviderOperation> operations, int index) {
    ContentProviderOperation.Builder builder;
    final int opIndex = index * 3;

    // create a Data record of common type 'StructuredName' for our RawContact
    builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
        .withValueBackReference(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, opIndex)
        .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
        .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, username);
    operations.add(builder.build());

    // create a Data record of custom type 'org.kontalk.user' to display a link to the conversation
    builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
        .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, opIndex)
        .withValue(ContactsContract.Data.MIMETYPE, Users.CONTENT_ITEM_TYPE)
        .withValue(DATA_COLUMN_DISPLAY_NAME, username)
        .withValue(DATA_COLUMN_ACCOUNT_NAME, mContext.getString(R.string.app_name))
        .withValue(DATA_COLUMN_PHONE, phone)
        .withYieldAllowed(true);
    operations.add(builder.build());
}
项目:haxsync    文件:ContactUtil.java   
public static void addEmail(Context c, long rawContactId, String email){
    DeviceUtil.log(c, "adding email", email);
    String where = ContactsContract.Data.RAW_CONTACT_ID + " = '" + rawContactId 
            + "' AND " + ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE+ "'";
    Cursor cursor = c.getContentResolver().query(ContactsContract.Data.CONTENT_URI, new String[] { RawContacts.CONTACT_ID}, where, null, null);
    if (cursor.getCount() == 0){
        ContentValues contentValues = new ContentValues();
        //op.put(ContactsContract.CommonDataKinds.StructuredPostal.CONTACT_ID, );
        contentValues.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE);
        contentValues.put(ContactsContract.Data.RAW_CONTACT_ID, rawContactId);
        contentValues.put(ContactsContract.CommonDataKinds.Email.ADDRESS, email);
        c.getContentResolver().insert(ContactsContract.Data.CONTENT_URI, contentValues);
    }
    cursor.close();

}
项目:CucumberSync    文件:LocalAddressBook.java   
private void populateStructuredName(Contact c) throws RemoteException {
    @Cleanup Cursor cursor = providerClient.query(dataURI(), new String[] {
            /* 0 */ StructuredName.DISPLAY_NAME, StructuredName.PREFIX, StructuredName.GIVEN_NAME,
            /* 3 */ StructuredName.MIDDLE_NAME, StructuredName.FAMILY_NAME, StructuredName.SUFFIX,
            /* 6 */ StructuredName.PHONETIC_GIVEN_NAME, StructuredName.PHONETIC_MIDDLE_NAME, StructuredName.PHONETIC_FAMILY_NAME
        }, StructuredName.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
        new String[] { String.valueOf(c.getLocalID()), StructuredName.CONTENT_ITEM_TYPE }, null);

    if (cursor != null && cursor.moveToNext()) {
        c.setDisplayName(cursor.getString(0));

        c.setPrefix(cursor.getString(1));
        c.setGivenName(cursor.getString(2));
        c.setMiddleName(cursor.getString(3));
        c.setFamilyName(cursor.getString(4));
        c.setSuffix(cursor.getString(5));

        c.setPhoneticGivenName(cursor.getString(6));
        c.setPhoneticMiddleName(cursor.getString(7));
        c.setPhoneticFamilyName(cursor.getString(8));
    }
}
项目:CucumberSync    文件:LocalAddressBook.java   
protected void populateEmailAddresses(Contact c) throws RemoteException {
    @Cleanup Cursor cursor = providerClient.query(dataURI(), new String[] { Email.TYPE, Email.ADDRESS, Email.LABEL, Email.IS_SUPER_PRIMARY },
            Email.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
            new String[] { String.valueOf(c.getLocalID()), Email.CONTENT_ITEM_TYPE }, null);
    while (cursor != null && cursor.moveToNext()) {
        ezvcard.property.Email email = new ezvcard.property.Email(cursor.getString(1));
        switch (cursor.getInt(0)) {
        case Email.TYPE_HOME:
            email.addType(EmailType.HOME);
            break;
        case Email.TYPE_WORK:
            email.addType(EmailType.WORK);
            break;
        case Email.TYPE_MOBILE:
            email.addType(Contact.EMAIL_TYPE_MOBILE);
            break;
        case Email.TYPE_CUSTOM:
            String customType = cursor.getString(2);
            if (!StringUtils.isEmpty(customType))
                email.addType(EmailType.get(labelToXName(customType)));
        }
        if (cursor.getInt(3) != 0)  // IS_PRIMARY
            email.addType(EmailType.PREF);
        c.getEmails().add(email);
    }
}
项目:CucumberSync    文件:LocalAddressBook.java   
protected void populatePhoto(Contact c) throws RemoteException {
    @Cleanup Cursor cursor = providerClient.query(dataURI(),
            new String[] { Photo.PHOTO_FILE_ID, Photo.PHOTO },
            Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
            new String[] { String.valueOf(c.getLocalID()), Photo.CONTENT_ITEM_TYPE }, null);
    if (cursor != null && cursor.moveToNext()) {
        if (!cursor.isNull(0)) {
            Uri photoUri = Uri.withAppendedPath(
                     ContentUris.withAppendedId(RawContacts.CONTENT_URI, c.getLocalID()),
                     RawContacts.DisplayPhoto.CONTENT_DIRECTORY);
            try {
                @Cleanup AssetFileDescriptor fd = providerClient.openAssetFile(photoUri, "r");
                @Cleanup InputStream is = fd.createInputStream();
                c.setPhoto(IOUtils.toByteArray(is));
            } catch(IOException ex) {
                Log.w(TAG, "Couldn't read high-res contact photo", ex);
            }
        } else
            c.setPhoto(cursor.getBlob(1));
    }
}
项目:yako    文件:FacebookFriendProvider.java   
private static Set<String> getContactsFacebookIds(final Activity activity) {

    Set<String> FacebookIds = new HashSet<String>();

    String selection = Data.MIMETYPE + " = ? "
            + " AND " + Data.DATA6 + " = ?";

    String[] selectionArgs = {
      ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE,
      Settings.Contacts.DataKinds.Facebook.CUSTOM_NAME
    };

    Cursor cursor = activity.getContentResolver().query(Data.CONTENT_URI,
            new String[]{Data.DATA10},
            selection,
            selectionArgs,
            null);

    while (cursor.moveToNext()) {
      FacebookIds.add(cursor.getString(0));
    }

    return FacebookIds;

  }
项目:CucumberSync    文件:LocalAddressBook.java   
protected void populateEvents(Contact c) throws RemoteException {
    @Cleanup Cursor cursor = providerClient.query(dataURI(), new String[] { CommonDataKinds.Event.TYPE, CommonDataKinds.Event.START_DATE },
            Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
            new String[] { String.valueOf(c.getLocalID()), CommonDataKinds.Event.CONTENT_ITEM_TYPE }, null);
    while (cursor != null && cursor.moveToNext()) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
        try {
            Date date = formatter.parse(cursor.getString(1));
            switch (cursor.getInt(0)) {
            case CommonDataKinds.Event.TYPE_ANNIVERSARY:
                c.setAnniversary(new Anniversary(date));
                break;
            case CommonDataKinds.Event.TYPE_BIRTHDAY:
                c.setBirthDay(new Birthday(date));
                break;
            }
        } catch (ParseException e) {
            Log.w(TAG, "Couldn't parse local birthday/anniversary date", e);
        }
    }
}
项目:CucumberSync    文件:LocalAddressBook.java   
protected void populateSipAddress(Contact c) throws RemoteException {
    @Cleanup Cursor cursor = providerClient.query(dataURI(),
            new String[] { SipAddress.SIP_ADDRESS, SipAddress.TYPE, SipAddress.LABEL },
            SipAddress.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
            new String[] { String.valueOf(c.getLocalID()), SipAddress.CONTENT_ITEM_TYPE }, null);
    if (cursor != null && cursor.moveToNext()) {
        Impp impp = new Impp("sip:" + cursor.getString(0));
        switch (cursor.getInt(1)) {
        case SipAddress.TYPE_HOME:
            impp.addType(ImppType.HOME);
            break;
        case SipAddress.TYPE_WORK:
            impp.addType(ImppType.WORK);
            break;
        case SipAddress.TYPE_CUSTOM:
            String customType = cursor.getString(2);
            if (!StringUtils.isEmpty(customType))
                impp.addType(ImppType.get(labelToXName(customType)));
        }
        c.getImpps().add(impp);
    }
}
项目:ContactMerger    文件:ContactDataMapper.java   
/**
 * Fetch the metadata of a single account. All results will be attached
 * to the contact.
 * @param contact The contact that should be enriched.
 */
private void fetchMetadata(RawContact contact) {
    try {
        Cursor cursor = provider.query(
                Data.CONTENT_URI,
                DATA_PROJECTION_MAP, 
                Data.RAW_CONTACT_ID + "=?",
                new String[]{Long.toString(contact.getID())},
                null);
        try {
            if (cursor.moveToFirst()) {
                do {
                    contact.setMetadata(newMetadata(cursor));
                } while (cursor.moveToNext());
            }
        } finally {
            cursor.close();
        }
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}
项目:CucumberSync    文件:LocalAddressBook.java   
protected Builder buildOrganization(Builder builder, Contact contact) {
    if (contact.getOrganization() == null && contact.getJobTitle() == null && contact.getJobDescription() == null)
        return null;

    ezvcard.property.Organization organization = contact.getOrganization();
    String company = null, department = null;
    if (organization != null) {
        Iterator<String> org = organization.getValues().iterator();
        if (org.hasNext())
            company = org.next();
        if (org.hasNext())
            department = org.next();
    }

    return builder
            .withValue(Data.MIMETYPE, Organization.CONTENT_ITEM_TYPE)
            .withValue(Organization.COMPANY, company)
            .withValue(Organization.DEPARTMENT, department)
            .withValue(Organization.TITLE, contact.getJobTitle())
            .withValue(Organization.JOB_DESCRIPTION, contact.getJobDescription());
}
项目:Securecom-Messaging    文件:ContactAccessor.java   
public List<ContactData> getGroupMembership(Context context, long groupId) {
    LinkedList<ContactData> contacts = new LinkedList<ContactData>();
    Cursor groupMembership = null;

    try {
        String selection = ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID + " = ? AND " +
                ContactsContract.CommonDataKinds.GroupMembership.MIMETYPE + " = ?";
        String[] args    = new String[] {groupId+"",
                ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE};

        groupMembership = context.getContentResolver().query(Data.CONTENT_URI, null, selection, args, null);

        while (groupMembership != null && groupMembership.moveToNext()) {
            String displayName = groupMembership.getString(groupMembership.getColumnIndexOrThrow(Data.DISPLAY_NAME));
            long contactId     = groupMembership.getLong(groupMembership.getColumnIndexOrThrow(Data.CONTACT_ID));

            contacts.add(getContactData(context, displayName, contactId));
        }
    } finally {
        if (groupMembership != null)
            groupMembership.close();
    }

    return contacts;
}
项目:Simplicissimus    文件:Assets.java   
public Assets(Context context, long contactId) {
    this.context = context;
    cursor = context.getContentResolver().query(
        Data.CONTENT_URI,
        new String[]{Data._ID,
            Data.RAW_CONTACT_ID, Data.MIMETYPE, Data.IS_PRIMARY,
            Data.IS_SUPER_PRIMARY, Data.DATA_VERSION, Data.DATA1,
            Data.DATA2, Data.DATA3, Data.DATA4, Data.DATA5, Data.DATA6,
            Data.DATA7, Data.DATA8, Data.DATA9, Data.DATA10, Data.DATA11,
            Data.DATA12, Data.DATA13, Data.DATA14, Data.DATA15, Data.SYNC1,
            Data.SYNC2, Data.SYNC3, Data.SYNC4, },
        Data.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + " IN ( ?, ?, ?, ?, ?, ? )",
        new String[]{
            String.valueOf(contactId),
            Nickname.CONTENT_ITEM_TYPE,
            Im.CONTENT_ITEM_TYPE,
            Photo.CONTENT_ITEM_TYPE,
            },
        null);
    //cursor.moveToFirst();
    columnNames = cursor.getColumnNames();
}
项目:Securecom-Text    文件:ContactAccessor.java   
public List<ContactData> getGroupMembership(Context context, long groupId) {
  LinkedList<ContactData> contacts = new LinkedList<ContactData>();
  Cursor groupMembership           = null;

  try {
    String selection = ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID + " = ? AND " +
                       ContactsContract.CommonDataKinds.GroupMembership.MIMETYPE + " = ?";
    String[] args    = new String[] {groupId+"",
                                     ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE};

    groupMembership = context.getContentResolver().query(Data.CONTENT_URI, null, selection, args, null);

    while (groupMembership != null && groupMembership.moveToNext()) {
      String displayName = groupMembership.getString(groupMembership.getColumnIndexOrThrow(Data.DISPLAY_NAME));
      long contactId     = groupMembership.getLong(groupMembership.getColumnIndexOrThrow(Data.CONTACT_ID));

      contacts.add(getContactData(context, displayName, contactId));
    }
  } finally {
    if (groupMembership != null)
      groupMembership.close();
  }

  return contacts;
}
项目:SafeSlinger-Android    文件:BaseActivity.java   
protected String getContactLookupKeyByContactId(String contactId) {
    if (!SafeSlinger.doesUserHavePermission(Manifest.permission.READ_CONTACTS)) {
        return null;
    }
    if (TextUtils.isEmpty(contactId)) {
        return null;
    }

    String where = Data.CONTACT_ID + " = ?";
    String[] whereParameters = new String[] {
        contactId
    };

    Cursor c = getContentResolver().query(Data.CONTENT_URI, null, where, whereParameters, null);
    if (c != null) {
        try {
            if (c.moveToFirst()) {
                String lookup = c.getString(c.getColumnIndexOrThrow(Data.LOOKUP_KEY));
                return lookup;
            }
        } finally {
            c.close();
        }
    }
    return null;
}
项目:SafeSlinger-Android    文件:BaseActivity.java   
protected String getContactLookupKeyByRawContactId(String rawContactId) {
    if (!SafeSlinger.doesUserHavePermission(Manifest.permission.READ_CONTACTS)) {
        return null;
    }
    if (TextUtils.isEmpty(rawContactId)) {
        return null;
    }

    String where = Data.RAW_CONTACT_ID + " = ?";
    String[] whereParameters = new String[] {
        rawContactId
    };

    Cursor c = getContentResolver().query(Data.CONTENT_URI, null, where, whereParameters, null);
    if (c != null) {
        try {
            if (c.moveToFirst()) {
                String lookup = c.getString(c.getColumnIndexOrThrow(Data.LOOKUP_KEY));
                return lookup;
            }
        } finally {
            c.close();
        }
    }
    return null;
}
项目:haxsync    文件:ContactUtil.java   
public static Photo getPhoto(ContentResolver c, long rawContactId){
    Photo photo = new Photo();
    String where = ContactsContract.Data.RAW_CONTACT_ID + " = '" + rawContactId 
            + "' AND " + ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'";



    Cursor c1 = c.query(ContactsContract.Data.CONTENT_URI, new String[] {ContactsContract.CommonDataKinds.Photo.PHOTO, ContactsContract.Data.SYNC2, ContactsContract.Data.SYNC3 }, where , null, null);
    if (c1.getCount() > 0){
        c1.moveToLast();
        photo.data = c1.getBlob(c1.getColumnIndex(ContactsContract.CommonDataKinds.Photo.PHOTO));
        photo.timestamp = Long.valueOf(c1.getString(c1.getColumnIndex(ContactsContract.Data.SYNC2)));
        photo.url = c1.getString(c1.getColumnIndex(ContactsContract.Data.SYNC3));
    }
    c1.close();
    return photo;
}
项目:SafeSlinger-Android    文件:ContactAccessorApi5.java   
public Uri getDataUri(ContentResolver resolver, String contactLookupKey) {
    if (!SafeSlinger.doesUserHavePermission(Manifest.permission.READ_CONTACTS)) {
        return null;
    }
    Uri lookupUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI,
            contactLookupKey);
    if (lookupUri != null) {
        Uri personUri = ContactsContract.Contacts.lookupContact(resolver, lookupUri);
        if (personUri != null) {
            return Uri.withAppendedPath(personUri,
                    ContactsContract.Contacts.Data.CONTENT_DIRECTORY);
        } else {
            return null;
        }
    } else {
        return null;
    }
}
项目:SafeSlinger-Android    文件:ContactAccessorApi5.java   
public boolean updateDataRow(Context ctx, String[] proj, String where, String[] args,
        ContentValues values) {
    Cursor c = ctx.getContentResolver().query(Data.CONTENT_URI, proj, where, args, null);
    if (c != null) {
        try {
            if (c.moveToFirst()) {
                // remove old, including dupes
                if (ctx.getContentResolver().delete(Data.CONTENT_URI, where, args) == 0) {
                    return false; // error
                }
            }
        } finally {
            c.close();
        }
    }
    if (ctx.getContentResolver().insert(Data.CONTENT_URI, values) != null)
        return true; // inserted a new entry or updated entry
    return false; // error
}
项目:SafeSlinger-Android    文件:ContactAccessorApi5.java   
private boolean updatePhoto(ContactStruct contact, String rawContactId, Context ctx) {

        // overwrite existing
        String[] proj = new String[] {
                Photo.RAW_CONTACT_ID, Data.MIMETYPE, Photo.PHOTO
        };
        String where = Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=? AND " + Photo.PHOTO
                + "!=NULL";
        String[] args = new String[] {
                rawContactId, Photo.CONTENT_ITEM_TYPE
        };
        ContentValues values = valuesPhoto(contact);
        values.put(Photo.RAW_CONTACT_ID, rawContactId);

        return updateDataRow(ctx, proj, where, args, values);
    }
项目:SafeSlinger-Android    文件:ContactAccessorApi5.java   
private boolean updateUrl(ContactMethod cmethod, String rawContactId, Context ctx) {

        // seek for raw contact + url = same
        String[] proj = new String[] {
                Website.RAW_CONTACT_ID, Data.MIMETYPE, Website.DATA
        };
        String where = Website.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=? AND "
                + Website.DATA + "=?";
        String[] args = new String[] {
                rawContactId, Website.CONTENT_ITEM_TYPE, cmethod.data
        };
        ContentValues values = valuesUrl(cmethod);
        values.put(Website.RAW_CONTACT_ID, rawContactId);

        return updateDataRow(ctx, proj, where, args, values);
    }
项目:SafeSlinger-Android    文件:ContactAccessorApi5.java   
private boolean updateEmail(ContactMethod cmethod, String rawContactId, Context ctx) {

        // seek for raw contact + email = same
        String[] proj = new String[] {
                Email.RAW_CONTACT_ID, Data.MIMETYPE, Email.DATA
        };
        String where = Email.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=? AND " + Email.DATA
                + "=?";
        String[] args = new String[] {
                rawContactId, Email.CONTENT_ITEM_TYPE, cmethod.data
        };
        ContentValues values = valuesEmail(cmethod);
        values.put(Email.RAW_CONTACT_ID, rawContactId);

        return updateDataRow(ctx, proj, where, args, values);
    }
项目:ContactMerger    文件:ContactDataMapper.java   
/**
 * Store all metadata info into a given contentvalues instance.
 * @param values A ContentValues instance.
 * @param metadata The Metadata instance to be saved to ContentValues.
 */
private void put(ContentValues values, Metadata metadata) {
    if (metadata.getID() > 0) {
        values.put(Data._ID, metadata.getID());
    }
    if (metadata.getRawContactID() > 0) {
        values.put(Data.RAW_CONTACT_ID, metadata.getRawContactID());
    }
    values.put(Data.MIMETYPE, metadata.getMimetype());
    for (int i = 0; i < SYNC_FIELDS.length; i++) {
        values.put(SYNC_FIELDS[i], metadata.getSync(i));
    }
    for (int i = 0; i < DATA_FIELDS.length; i++) {
        values.put(DATA_FIELDS[i], metadata.getData(i));
    }
    values.put(Data.DATA15, metadata.getBlob());
}
项目:SafeSlinger-Android    文件:ContactAccessorApi5.java   
private boolean updatePostal(Address postal, String rawContactId, Context ctx) {

        // seek for raw contact + formatted address = same
        String[] proj = new String[] {
                StructuredPostal.RAW_CONTACT_ID, Data.MIMETYPE, StructuredPostal.FORMATTED_ADDRESS
        };
        String where = StructuredPostal.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=? AND "
                + StructuredPostal.FORMATTED_ADDRESS + "=?";
        String[] args = new String[] {
                rawContactId, StructuredPostal.CONTENT_ITEM_TYPE, postal.toString()
        };
        ContentValues values = valuesPostal(postal);
        values.put(StructuredPostal.RAW_CONTACT_ID, rawContactId);

        return updateDataRow(ctx, proj, where, args, values);
    }
项目:SafeSlinger-Android    文件:ContactAccessorApi5.java   
private boolean updatePhone(PhoneData phone, String rawContactId, Context ctx) {

        // seek for raw contact + number = same
        String[] proj = new String[] {
                Phone.RAW_CONTACT_ID, Data.MIMETYPE, Phone.NUMBER
        };
        String where = Phone.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=? AND " + Phone.NUMBER
                + "=?";
        String[] args = new String[] {
                rawContactId, Phone.CONTENT_ITEM_TYPE, phone.data
        };
        ContentValues values = valuesPhone(phone);
        values.put(Phone.RAW_CONTACT_ID, rawContactId);

        return updateDataRow(ctx, proj, where, args, values);
    }
项目:haxsync    文件:ContactUtil.java   
public static void addBirthday(long rawContactId, String birthday){
    String where = ContactsContract.Data.RAW_CONTACT_ID + " = '" + rawContactId 
            + "' AND " + ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE
            + "' AND " + ContactsContract.CommonDataKinds.Event.TYPE + " = '" + ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY + "'";
    Cursor cursor = ContactsSyncAdapterService.mContentResolver.query(ContactsContract.Data.CONTENT_URI, null, where, null, null);
    int count = cursor.getCount();
    cursor.close();
    if (count <= 0){
        ContentValues contentValues = new ContentValues();
        contentValues.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE);
        contentValues.put(ContactsContract.Data.RAW_CONTACT_ID, rawContactId);
        contentValues.put(ContactsContract.CommonDataKinds.Event.TYPE, ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY);
        contentValues.put(ContactsContract.CommonDataKinds.Event.START_DATE, birthday);

        try {
            ContactsSyncAdapterService.mContentResolver.insert(ContactsContract.Data.CONTENT_URI, contentValues);
        //  mContentResolver.applyBatch(ContactsContract.AUTHORITY, operationList);
        } catch (Exception e) {
            e.printStackTrace();
            //Log.e("ERROR:" , e.^);
        }
    }
}
项目:JCB    文件:ContactUtils.java   
private String getNote(String contactId) {
    Cursor cursor = cr.query(Data.CONTENT_URI, new String[] { Data._ID,
            Note.NOTE }, Data.CONTACT_ID + "=?" + " AND " + Data.MIMETYPE
            + "='" + Note.CONTENT_ITEM_TYPE + "'",
            new String[] { contactId }, null);
    StringBuffer sb = new StringBuffer();
    if (cursor.moveToFirst()) {

        do {
            String noteinfo = cursor.getString(cursor
                    .getColumnIndex(Note.NOTE));
            sb.append(noteinfo);
        } while (cursor.moveToNext());
    } else {
        sb.append("");
    }
    cursor.close();
    return sb.toString();
}