android.provider.ContactsContract.CommonDataKinds.Note#android.provider.ContactsContract.RawContacts源码实例Demo

下面列出了android.provider.ContactsContract.CommonDataKinds.Note#android.provider.ContactsContract.RawContacts 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: mollyim-android   文件: ContactsDatabase.java
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)});
    }
  }
}
 
源代码2 项目: mollyim-android   文件: ContactsDatabase.java
private void addContactVoiceSupport(List<ContentProviderOperation> operations,
                                    @NonNull String address, long rawContactId)
{
  operations.add(ContentProviderOperation.newUpdate(RawContacts.CONTENT_URI)
                                         .withSelection(RawContacts._ID + " = ?", new String[] {String.valueOf(rawContactId)})
                                         .withValue(RawContacts.SYNC4, "true")
                                         .build());

  operations.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build())
                                         .withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactId)
                                         .withValue(ContactsContract.Data.MIMETYPE, CALL_MIMETYPE)
                                         .withValue(ContactsContract.Data.DATA1, address)
                                         .withValue(ContactsContract.Data.DATA2, context.getString(R.string.app_name))
                                         .withValue(ContactsContract.Data.DATA3, context.getString(R.string.ContactsDatabase_signal_call_s, address))
                                         .withYieldAllowed(true)
                                         .build());
}
 
源代码3 项目: 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());
}
 
源代码4 项目: mobilecloud-15   文件: InsertContactsCommand.java
/**
 * Each contact requires two (asynchronous) insertions into
 * the Contacts Provider.  The first insert puts the
 * RawContact into the Contacts Provider and the second insert
 * puts the data associated with the RawContact into the
 * Contacts Provider.
 */
public void executeImpl() {
    if (getArgs().getIterator().hasNext()) {
        // If there are any contacts left to insert, make a
        // ContentValues object containing the RawContact
        // portion of the contact and initiate an asynchronous
        // insert on the Contacts ContentProvider.
        final ContentValues values = makeRawContact(1);
        getArgs().getAdapter()
                 .startInsert(this,
                              INSERT_RAW_CONTACT,
                              RawContacts.CONTENT_URI,
                              values);
    } else
        // Otherwise, print a toast with summary info.
        Utils.showToast(getArgs().getOps().getActivityContext(),
                        getArgs().getCounter().getValue()
                        +" contact(s) inserted");
}
 
源代码5 项目: 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());
}
 
源代码6 项目: linphone-android   文件: AndroidContact.java
private String findRawContactID() {
    ContentResolver resolver =
            LinphoneContext.instance().getApplicationContext().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[] {mAndroidId},
                    null);
    if (c != null) {
        if (c.moveToFirst()) {
            result = c.getString(c.getColumnIndex(ContactsContract.RawContacts._ID));
        }
        c.close();
    }
    return result;
}
 
源代码7 项目: coursera-android   文件: DisplayActivity.java
private void addRecordToBatchInsertOperation(String name,
		List<ContentProviderOperation> ops) {

	int position = ops.size();

	// First part of operation
	ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
			.withValue(RawContacts.ACCOUNT_TYPE, mType)
			.withValue(RawContacts.ACCOUNT_NAME, mName)
			.withValue(Contacts.STARRED, 1).build());

	// Second part of operation
	ops.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());

}
 
源代码8 项目: coursera-android   文件: DisplayActivity.java
private void addRecordToBatchInsertOperation(String name,
                                             List<ContentProviderOperation> ops) {

    int position = ops.size();

    // First part of operation
    ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
            .withValue(RawContacts.ACCOUNT_TYPE, mType)
            .withValue(RawContacts.ACCOUNT_NAME, mName)
            .withValue(Contacts.STARRED, 1).build());

    // Second part of operation
    ops.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());

}
 
源代码9 项目: haxsync   文件: ContactDetailFragment.java
private void getContactDetails(long id){
Cursor cursor = getActivity().getContentResolver().query(RawContacts.CONTENT_URI, new String[] {RawContacts._ID, RawContacts.DISPLAY_NAME_PRIMARY, RawContacts.CONTACT_ID, RawContacts.SYNC1}, RawContacts._ID + "=" +id, null, null);
if (cursor.getColumnCount() >= 1){
	cursor.moveToFirst();
	name = cursor.getString(cursor.getColumnIndex(RawContacts.DISPLAY_NAME_PRIMARY));
	uid = cursor.getString(cursor.getColumnIndex(RawContacts.SYNC1));
	joined = ContactUtil.getMergedContacts(getActivity(), id);
	contactID = cursor.getLong(cursor.getColumnIndex(RawContacts.CONTACT_ID));
	
}
cursor.close();
imageURI = Uri.withAppendedPath(
ContentUris.withAppendedId(RawContacts.CONTENT_URI, id),
      RawContacts.DisplayPhoto.CONTENT_DIRECTORY);
Log.i("imageuri", imageURI.toString());
  }
 
源代码10 项目: haxsync   文件: ContactListFragment.java
@Override
  public void onActivityCreated(Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
      
      setEmptyText(getActivity().getString(R.string.no_contacts));
      setHasOptionsMenu(true);


String[] columns = new String[] {RawContacts.DISPLAY_NAME_PRIMARY};
int[] to = new int[] { android.R.id.text1 };
mAdapter = new ContactsCursorAdapter(
        getActivity(),
        android.R.layout.simple_list_item_activated_1, 
        null,
        columns,
        to,
        0);
setListAdapter(mAdapter);
showSyncIndicator();
   mContentProviderHandle = ContentResolver.addStatusChangeListener(
             ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE, this);

  }
 
源代码11 项目: haxsync   文件: ContactUtil.java
public static Contact getMergedContact(Context c, long contactID, Account account){
  	
Uri ContactUri = RawContacts.CONTENT_URI.buildUpon()
		.appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name)
		.appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type)
		.build();
  	
Cursor cursor = c.getContentResolver().query(ContactUri, new String[] { BaseColumns._ID, RawContacts.DISPLAY_NAME_PRIMARY}, RawContacts.CONTACT_ID +" = '" + contactID + "'", null, null);
if (cursor.getCount() > 0){
	cursor.moveToFirst();
	Contact contact = new Contact();
	contact.ID = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID));
	contact.name = cursor.getString(cursor.getColumnIndex(RawContacts.DISPLAY_NAME_PRIMARY));
	cursor.close();
	return contact;
}
cursor.close();
return null;

  }
 
源代码12 项目: haxsync   文件: ContactUtil.java
public static Set<Long> getRawContacts(ContentResolver c, long rawContactID, String accountType){
	HashSet<Long> ids = new HashSet<Long>();
	Cursor cursor = c.query(RawContacts.CONTENT_URI, new String[] { RawContacts.CONTACT_ID}, RawContacts._ID +" = '" + rawContactID + "'", null, null);	
	if (cursor.getCount() > 0){
		cursor.moveToFirst();
		long contactID = cursor.getLong(cursor.getColumnIndex(RawContacts.CONTACT_ID));
		//	Log.i("QUERY", RawContacts.CONTACT_ID +" = '" + contactID + "'" + " AND " + BaseColumns._ID + " != " +rawContactID + " AND " + RawContacts.ACCOUNT_TYPE + " = '" + accountType+"'");
			Cursor c2 = c.query(RawContacts.CONTENT_URI, new String[] { BaseColumns._ID}, RawContacts.CONTACT_ID +" = '" + contactID + "'" + " AND " + BaseColumns._ID + " != " +rawContactID + " AND " + RawContacts.ACCOUNT_TYPE + " = '" + accountType+"'", null, null);
		//	Log.i("CURSOR SIZE", String.valueOf(c2.getCount()));
			while (c2.moveToNext()){
				ids.add(c2.getLong(c2.getColumnIndex(BaseColumns._ID)));
			}
			c2.close();
	}
	cursor.close();
	return ids;
}
 
源代码13 项目: 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();

}
 
源代码14 项目: ContactMerger   文件: ContactDataMapper.java
/**
 * <p>Delete a set of contacts based on their id.</p>
 * <p><i>Note:</i> the method used for bulk delete is a group selection
 * based on id (<i>{@ling BaseColumns#_ID} IN (id1, id2, ...)</i>).
 * @param ids The IDs if all users that should be deleted.
 */
public void bulkDelete(long[] ids) {
    if (ids.length == 0) {
        return;
    }
    StringBuilder where = new StringBuilder();
    where.append(RawContacts._ID);
    where.append(" IN (");
    where.append(Long.toString(ids[0]));
    for (int i = 1; i < ids.length; i++) {
        where.append(',');
        where.append(Long.toString(ids[i]));
    }
    where.append(')');
    try {
        provider.delete(RawContacts.CONTENT_URI, where.toString(), null);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}
 
源代码15 项目: ContactMerger   文件: ContactDataMapper.java
public int getContactByRawContactID(long id) {
    int result = -1;
    try {
        Cursor cursor = provider.query(
                RawContacts.CONTENT_URI,
                CONTACT_OF_RAW_CONTACT_PROJECTION,
                RawContacts._ID + "=" + id,
                null,
                null);
        try {
            if (cursor.moveToFirst()) {
                result = cursor.getInt(cursor.getColumnIndex(
                            RawContacts.CONTACT_ID));
            }
        } finally {
            cursor.close();
        }
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    return result;
}
 
源代码16 项目: ContactMerger   文件: ContactDataMapper.java
/**
 * Retrieve a single jid as bound by a local account jid, with or without
 * metadata.
 * @param accountJid The local account jid.
 * @param jid The remote jid.
 * @param metadata True if a second fetch for metadata should be done.
 * @return A single contact.
 */
public RawContact getRawContactByJid(String accountJid, String jid, boolean metadata) {
    RawContact contact = null;
    try {
        Cursor cursor = provider.query(
                RawContacts.CONTENT_URI,
                RAW_CONTACT_PROJECTION_MAP, 
                RawContacts.ACCOUNT_NAME + "=? AND " +
                RawContacts.SOURCE_ID + "=?",
                new String[]{accountJid, jid},
                null);
        try {
            if (cursor.moveToFirst()) {
                contact = newRawContact(cursor);
                if (metadata) {
                    fetchMetadata(contact);
                }
            }
        } finally {
            cursor.close();
        }
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    return contact;
}
 
源代码17 项目: ContactMerger   文件: ContactDataMapper.java
/**
 * Create a new raw contact for the current cursor.
 * @param cursor The DB cursor, scrolled to the row in question.
 * @return
 */
private RawContact newRawContact(Cursor cursor) {
    RawContact contact = new RawContact();
    int index = cursor.getColumnIndex(RawContacts._ID);
    contact.setID(cursor.getLong(index));

    index = cursor.getColumnIndex(RawContacts.ACCOUNT_NAME);
    contact.setAccountName(cursor.getString(index));

    index = cursor.getColumnIndex(RawContacts.ACCOUNT_TYPE);
    contact.setAccountType(cursor.getString(index));

    index = cursor.getColumnIndex(RawContacts.SOURCE_ID);
    contact.setSourceID(cursor.getString(index));

    for (int i = 0; i < RAW_CONTACTS_SYNC_FIELDS.length; i++) {
        index = cursor.getColumnIndex(RAW_CONTACTS_SYNC_FIELDS[i]);
        contact.setSync(i, cursor.getString(index));
    }
    return contact;
}
 
源代码18 项目: mollyim-android   文件: ContactsDatabase.java
private void removeTextSecureRawContact(List<ContentProviderOperation> operations,
                                        Account account, long rowId)
{
  operations.add(ContentProviderOperation.newDelete(RawContacts.CONTENT_URI.buildUpon()
                                                                           .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name)
                                                                           .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type)
                                                                           .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build())
                                         .withYieldAllowed(true)
                                         .withSelection(BaseColumns._ID + " = ?", new String[] {String.valueOf(rowId)})
                                         .build());
}
 
源代码19 项目: mollyim-android   文件: ContactsDatabase.java
private @NonNull Map<String, SignalContact> getSignalRawContacts(@NonNull Account account) {
  Uri currentContactsUri = RawContacts.CONTENT_URI.buildUpon()
                                                  .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name)
                                                  .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type).build();

  Map<String, SignalContact> signalContacts = new HashMap<>();
  Cursor                     cursor         = null;

  try {
    String[] projection = new String[] {BaseColumns._ID, RawContacts.SYNC1, RawContacts.SYNC4, RawContacts.CONTACT_ID, RawContacts.DISPLAY_NAME_PRIMARY, RawContacts.DISPLAY_NAME_SOURCE};

    cursor = context.getContentResolver().query(currentContactsUri, projection, null, null, null);

    while (cursor != null && cursor.moveToNext()) {
      String  currentAddress              = PhoneNumberFormatter.get(context).format(cursor.getString(1));
      long    rawContactId                = cursor.getLong(0);
      long    contactId                   = cursor.getLong(3);
      String  supportsVoice               = cursor.getString(2);
      String  rawContactDisplayName       = cursor.getString(4);
      String  aggregateDisplayName        = getDisplayName(contactId);
      int     rawContactDisplayNameSource = cursor.getInt(5);

      signalContacts.put(currentAddress, new SignalContact(rawContactId, supportsVoice, rawContactDisplayName, aggregateDisplayName, rawContactDisplayNameSource));
    }
  } finally {
    if (cursor != null)
      cursor.close();
  }

  return signalContacts;
}
 
源代码20 项目: mollyim-android   文件: ContactsDatabase.java
private Optional<SystemContactInfo> getSystemContactInfo(@NonNull String address)
{
  Uri      uri          = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address));
  String[] projection   = {ContactsContract.PhoneLookup.NUMBER,
                           ContactsContract.PhoneLookup._ID,
                           ContactsContract.PhoneLookup.DISPLAY_NAME};
  Cursor   numberCursor = null;
  Cursor   idCursor     = null;

  try {
    numberCursor = context.getContentResolver().query(uri, projection, null, null, null);

    while (numberCursor != null && numberCursor.moveToNext()) {
      String systemNumber  = numberCursor.getString(0);
      String systemAddress = PhoneNumberFormatter.get(context).format(systemNumber);

      if (systemAddress.equals(address)) {
        idCursor = context.getContentResolver().query(RawContacts.CONTENT_URI,
                                                      new String[] {RawContacts._ID},
                                                      RawContacts.CONTACT_ID + " = ? ",
                                                      new String[] {String.valueOf(numberCursor.getLong(1))},
                                                      null);

        if (idCursor != null && idCursor.moveToNext()) {
          return Optional.of(new SystemContactInfo(numberCursor.getString(2),
                                                   numberCursor.getString(0),
                                                   idCursor.getLong(0)));
        }
      }
    }
  } finally {
    if (numberCursor != null) numberCursor.close();
    if (idCursor     != null) idCursor.close();
  }

  return Optional.absent();
}
 
源代码21 项目: SmartChart   文件: CommonUtils.java
/**
 * 往手机通讯录插入联系人
 *
 * @param ct
 * @param name
 * @param tel
 * @param email
 */
public static void insertContact(Context ct, String name, String tel, String email) {
    ContentValues values = new ContentValues();
    // 首先向RawContacts.CONTENT_URI执行一个空值插入,目的是获取系统返回的rawContactId
    Uri rawContactUri = ct.getContentResolver().insert(RawContacts.CONTENT_URI, values);
    long rawContactId = ContentUris.parseId(rawContactUri);
    // 往data表入姓名数据
    if (!TextUtils.isEmpty(tel)) {
        values.clear();
        values.put(Data.RAW_CONTACT_ID, rawContactId);
        values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);// 内容类型
        values.put(StructuredName.GIVEN_NAME, name);
        ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
    }
    // 往data表入电话数据
    if (!TextUtils.isEmpty(tel)) {
        values.clear();
        values.put(Data.RAW_CONTACT_ID, rawContactId);
        values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);// 内容类型
        values.put(Phone.NUMBER, tel);
        values.put(Phone.TYPE, Phone.TYPE_MOBILE);
        ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
    }
    // 往data表入Email数据
    if (!TextUtils.isEmpty(email)) {
        values.clear();
        values.put(Data.RAW_CONTACT_ID, rawContactId);
        values.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);// 内容类型
        values.put(Email.DATA, email);
        values.put(Email.TYPE, Email.TYPE_WORK);
        ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
    }
}
 
源代码22 项目: BigApp_Discuz_Android   文件: ContactUtils.java
public static void insertContact(Context context, String name, String phone) {
	// 首先插入空值,再得到rawContactsId ,用于下面插值
	ContentValues values = new ContentValues();
	// insert a null value
	Uri rawContactUri = context.getContentResolver().insert(
			RawContacts.CONTENT_URI, values);
	long rawContactsId = ContentUris.parseId(rawContactUri);

	// 往刚才的空记录中插入姓名
	values.clear();
	// A reference to the _ID that this data belongs to
	values.put(StructuredName.RAW_CONTACT_ID, rawContactsId);
	// "CONTENT_ITEM_TYPE" MIME type used when storing this in data table
	values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
	// The name that should be used to display the contact.
	values.put(StructuredName.DISPLAY_NAME, name);
	// insert the real values
	context.getContentResolver().insert(Data.CONTENT_URI, values);
	// 插入电话
	values.clear();
	values.put(Phone.RAW_CONTACT_ID, rawContactsId);
	// String "Data.MIMETYPE":The MIME type of the item represented by this
	// row
	// String "CONTENT_ITEM_TYPE": MIME type used when storing this in data
	// table.
	values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
	values.put(Phone.NUMBER, phone);
	context.getContentResolver().insert(Data.CONTENT_URI, values);
}
 
源代码23 项目: tindroid   文件: ContactOperations.java
private ContactOperations(Context context, String uid, String accountName,
                         BatchOperation batchOperation, boolean isSyncContext) {
    this(context, batchOperation, isSyncContext);

    mBackReference = mBatchOperation.size();
    mIsNewContact = true;
    mValues.put(RawContacts.SOURCE_ID, uid);
    mValues.put(RawContacts.ACCOUNT_TYPE, Utils.ACCOUNT_TYPE);
    mValues.put(RawContacts.ACCOUNT_NAME, accountName);

    mBatchOperation.add(newInsertCpo(RawContacts.CONTENT_URI, mIsSyncContext).withValues(mValues).build());
}
 
源代码24 项目: showCaseCordova   文件: ContactManager.java
/**
 * Called when user picks contact.
 * @param requestCode       The request code originally supplied to startActivityForResult(),
 *                          allowing you to identify who this result came from.
 * @param resultCode        The integer result code returned by the child activity through its setResult().
 * @param intent            An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
 * @throws JSONException
 */
public void onActivityResult(int requestCode, int resultCode, final Intent intent) {
    if (requestCode == CONTACT_PICKER_RESULT) {
        if (resultCode == Activity.RESULT_OK) {
            String contactId = intent.getData().getLastPathSegment();
            // to populate contact data we require  Raw Contact ID
            // so we do look up for contact raw id first
            Cursor c =  this.cordova.getActivity().getContentResolver().query(RawContacts.CONTENT_URI,
                        new String[] {RawContacts._ID}, RawContacts.CONTACT_ID + " = " + contactId, null, null);
            if (!c.moveToFirst()) {
                this.callbackContext.error("Error occured while retrieving contact raw id");
                return;
            }
            String id = c.getString(c.getColumnIndex(RawContacts._ID));
            c.close();

            try {
                JSONObject contact = contactAccessor.getContactById(id);
                this.callbackContext.success(contact);
                return;
            } catch (JSONException e) {
                Log.e(LOG_TAG, "JSON fail.", e);
            }
        } else if (resultCode == Activity.RESULT_CANCELED){
            this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.NO_RESULT, UNKNOWN_ERROR));
            return;
        }
        this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, UNKNOWN_ERROR));
    }
}
 
源代码25 项目: mobilecloud-15   文件: InsertContactsCommand.java
/**
 * Factory method that creates a ContentValues containing the
 * RawContact associated with the account type/name.
 */
private ContentValues makeRawContact(int starred) {
    ContentValues values = new ContentValues();
    values.put(RawContacts.ACCOUNT_TYPE,
               getArgs().getOps().getAccountType());
    values.put(RawContacts.ACCOUNT_NAME,
               getArgs().getOps().getAccountName());
    values.put(Contacts.STARRED,
               starred);
    return values;
}
 
源代码26 项目: linphone-android   文件: AndroidContact.java
void createAndroidContact() {
    if (LinphoneContext.instance()
            .getApplicationContext()
            .getResources()
            .getBoolean(R.bool.use_linphone_tag)) {
        Log.i("[Contact] Creating contact using linphone account type");
        addChangesToCommit(
                ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
                        .withValue(
                                RawContacts.ACCOUNT_TYPE,
                                ContactsManager.getInstance()
                                        .getString(R.string.sync_account_type))
                        .withValue(
                                RawContacts.ACCOUNT_NAME,
                                ContactsManager.getInstance()
                                        .getString(R.string.sync_account_name))
                        .withValue(
                                RawContacts.AGGREGATION_MODE,
                                RawContacts.AGGREGATION_MODE_DEFAULT)
                        .build());
        isAndroidRawIdLinphone = true;

    } else {
        Log.i("[Contact] Creating contact using default account type");
        addChangesToCommit(
                ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
                        .withValue(RawContacts.ACCOUNT_TYPE, null)
                        .withValue(RawContacts.ACCOUNT_NAME, null)
                        .withValue(
                                RawContacts.AGGREGATION_MODE,
                                RawContacts.AGGREGATION_MODE_DEFAULT)
                        .build());
    }
}
 
源代码27 项目: linphone-android   文件: AndroidContact.java
private void createRawLinphoneContactFromExistingAndroidContact() {
    addChangesToCommit(
            ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
                    .withValue(
                            ContactsContract.RawContacts.ACCOUNT_TYPE,
                            ContactsManager.getInstance().getString(R.string.sync_account_type))
                    .withValue(
                            ContactsContract.RawContacts.ACCOUNT_NAME,
                            ContactsManager.getInstance().getString(R.string.sync_account_name))
                    .withValue(
                            ContactsContract.RawContacts.AGGREGATION_MODE,
                            ContactsContract.RawContacts.AGGREGATION_MODE_DEFAULT)
                    .build());

    addChangesToCommit(
            ContentProviderOperation.newUpdate(
                            ContactsContract.AggregationExceptions.CONTENT_URI)
                    .withValue(
                            ContactsContract.AggregationExceptions.TYPE,
                            ContactsContract.AggregationExceptions.TYPE_KEEP_TOGETHER)
                    .withValue(
                            ContactsContract.AggregationExceptions.RAW_CONTACT_ID1,
                            mAndroidRawId)
                    .withValueBackReference(
                            ContactsContract.AggregationExceptions.RAW_CONTACT_ID2, 0)
                    .build());

    Log.i(
            "[Contact] Creating linphone RAW contact for contact "
                    + mAndroidId
                    + " linked with existing RAW contact "
                    + mAndroidRawId);
    saveChangesCommited();
}
 
源代码28 项目: linphone-android   文件: AndroidContact.java
private String findLinphoneRawContactId() {
    ContentResolver resolver =
            LinphoneContext.instance().getApplicationContext().getContentResolver();
    String result = null;
    String[] projection = {ContactsContract.RawContacts._ID};

    String selection =
            ContactsContract.RawContacts.CONTACT_ID
                    + "=? AND "
                    + ContactsContract.RawContacts.ACCOUNT_TYPE
                    + "=?";
    Cursor c =
            resolver.query(
                    ContactsContract.RawContacts.CONTENT_URI,
                    projection,
                    selection,
                    new String[] {
                        mAndroidId,
                        ContactsManager.getInstance().getString(R.string.sync_account_type)
                    },
                    null);
    if (c != null) {
        if (c.moveToFirst()) {
            result = c.getString(c.getColumnIndex(ContactsContract.RawContacts._ID));
        }
        c.close();
    }
    return result;
}
 
源代码29 项目: haxsync   文件: ContactListFragment.java
@Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
	Activity ac = getActivity();
	AccountManager am = AccountManager.get(ac);
	Account account = am.getAccountsByType(ac.getString(R.string.ACCOUNT_TYPE))[0];
	Uri rawContactUri = RawContacts.CONTENT_URI.buildUpon()
				.appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name)
				.appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type)
				.build();

	return new CursorLoader(ac, rawContactUri,
			new String[] {RawContacts._ID, RawContacts.DISPLAY_NAME_PRIMARY},
			null, null, RawContacts.DISPLAY_NAME_PRIMARY + " ASC");
}
 
源代码30 项目: haxsync   文件: ContactListFragment.java
public Cursor swapCursor(Cursor c) {
    // Create our indexer
    if (c != null) {
        mAlphaIndexer = new AlphabetIndexer(c, c.getColumnIndex(RawContacts.DISPLAY_NAME_PRIMARY),
            " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    }
    return super.swapCursor(c);
}