android.provider.ContactsContract.RawContacts Java Examples

The following examples show how to use android.provider.ContactsContract.RawContacts. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InsertContactsCommand.java    From mobilecloud-15 with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example #2
Source File: ContactDetailFragment.java    From haxsync with GNU General Public License v2.0 6 votes vote down vote up
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());
  }
 
Example #3
Source File: ContactListFragment.java    From haxsync with GNU General Public License v2.0 6 votes vote down vote up
@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);

  }
 
Example #4
Source File: DisplayActivity.java    From coursera-android with MIT License 6 votes vote down vote up
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());

}
 
Example #5
Source File: DisplayActivity.java    From coursera-android with MIT License 6 votes vote down vote up
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());

}
 
Example #6
Source File: AndroidContact.java    From linphone-android with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #7
Source File: InsertContactsCommand.java    From mobilecloud-15 with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example #8
Source File: InsertContactsCommand.java    From mobilecloud-15 with Apache License 2.0 6 votes vote down vote up
/**
 * 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");
}
 
Example #9
Source File: ContactUtil.java    From haxsync with GNU General Public License v2.0 6 votes vote down vote up
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;

  }
 
Example #10
Source File: ContactUtil.java    From haxsync with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #11
Source File: ContactsDatabase.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
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());
}
 
Example #12
Source File: ContactsDatabase.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public synchronized  void removeDeletedRawContacts(@NonNull Account account) {
  Uri currentContactsUri = RawContacts.CONTENT_URI.buildUpon()
                                                  .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name)
                                                  .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type)
                                                  .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true")
                                                  .build();

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

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

      context.getContentResolver().delete(currentContactsUri, RawContacts._ID + " = ?", new String[] {String.valueOf(rawContactId)});
    }
  }
}
 
Example #13
Source File: ContactDataMapper.java    From ContactMerger with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #14
Source File: ContactDataMapper.java    From ContactMerger with Apache License 2.0 6 votes vote down vote up
/**
 * <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();
    }
}
 
Example #15
Source File: ContactDataMapper.java    From ContactMerger with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #16
Source File: ContactUtil.java    From haxsync with GNU General Public License v2.0 6 votes vote down vote up
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();

}
 
Example #17
Source File: ContactDataMapper.java    From ContactMerger with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #18
Source File: Preferences.java    From haxsync with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Void doInBackground(Void... params) {
	Uri rawContactUri = RawContacts.CONTENT_URI.buildUpon()
			.appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name)
			.appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type)
			.build();
	Cursor c1 = context.getContentResolver().query(rawContactUri, new String[] { BaseColumns._ID}, null, null, null);
	while (c1.moveToNext()){
		ContactUtil.removeEmails(context, c1.getLong(c1.getColumnIndex(BaseColumns._ID)));
	}

	return null;
}
 
Example #19
Source File: ContactListFragment.java    From haxsync with GNU General Public License v2.0 5 votes vote down vote up
@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");
}
 
Example #20
Source File: ContactDataMapper.java    From ContactMerger with Apache License 2.0 5 votes vote down vote up
/**
 * Add all contact data to a content values instance.
 * @param values The ContentValues instance.
 * @param contact The contact to be copied into the values parameter.
 */
private void put(ContentValues values, RawContact contact) {
    if (contact.getID() > 0) {
        values.put(RawContacts._ID, contact.getID());
    }
    values.put(RawContacts.ACCOUNT_NAME, contact.getAccountName());
    values.put(RawContacts.ACCOUNT_TYPE, contact.getAccountType());
    values.put(RawContacts.SOURCE_ID, contact.getSourceID());
    for (int i = 0; i < RAW_CONTACTS_SYNC_FIELDS.length; i++) {
        values.put(RAW_CONTACTS_SYNC_FIELDS[i], contact.getSync(i));
    }
}
 
Example #21
Source File: ContactListFragment.java    From haxsync with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #22
Source File: Preferences.java    From haxsync with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Void doInBackground(Void... params) {
	Uri rawContactUri = RawContacts.CONTENT_URI.buildUpon()
			.appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name)
			.appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type)
			.build();
	Cursor c1 = context.getContentResolver().query(rawContactUri, new String[] { BaseColumns._ID}, null, null, null);
	while (c1.moveToNext()){
		ContactUtil.removeBirthdays(context, c1.getLong(c1.getColumnIndex(BaseColumns._ID)));
	}

	return null;
}
 
Example #23
Source File: ContactsSyncAdapterService.java    From haxsync with GNU General Public License v2.0 5 votes vote down vote up
public static HashMap<String, SyncEntry> getLocalContacts(Account account){
	Uri rawContactUri = RawContacts.CONTENT_URI.buildUpon()
			.appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name)
			.appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type)
			.build();
	HashMap<String, SyncEntry> localContacts = new HashMap<String, SyncEntry>();
	Cursor c1 = mContentResolver.query(rawContactUri, new String[] { BaseColumns._ID, UsernameColumn, PhotoTimestampColumn }, null, null, null);
	while (c1.moveToNext()) {
		SyncEntry entry = new SyncEntry();
		entry.raw_id = c1.getLong(c1.getColumnIndex(BaseColumns._ID));
		localContacts.put(c1.getString(1), entry);
	}
	c1.close();
	return localContacts;
}
 
Example #24
Source File: CalendarSyncAdapterService.java    From haxsync with GNU General Public License v2.0 5 votes vote down vote up
private static Set<String> getFriends(Context context, Account account){
	HashSet<String> friends = new HashSet<String>();
	Uri rawContactUri = RawContacts.CONTENT_URI.buildUpon()
			.appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name)
			.appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type)
			.build();
	Cursor c1 = mContentResolver.query(rawContactUri, new String[] { RawContacts.DISPLAY_NAME_PRIMARY }, null, null, null);
	while (c1.moveToNext()) {
		friends.add(c1.getString(0));
	}
	c1.close();
	return friends;
}
 
Example #25
Source File: ContactManager.java    From jpHolo with MIT License 5 votes vote down vote up
/**
 * 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));
    }
}
 
Example #26
Source File: ContactDataMapper.java    From ContactMerger with Apache License 2.0 5 votes vote down vote up
/**
 * Append all operations needed to store the current contact to a set of
 * operations.
 * @param contact The current contact with metadata.
 * @param operations A set of operations to be extended.
 */
public void persist(RawContact contact, ArrayList<ContentProviderOperation> operations) {
    int operationsStart = operations.size();
    Builder operation;
    if (contact.getID() == -1) {
        operation = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI);
    } else {
        operation = ContentProviderOperation.newUpdate(RawContacts.CONTENT_URI);
        operation.withSelection(RawContacts._ID + "=?", new String[]{Long.toString(contact.getID())});
    }
    ContentValues values = new ContentValues();
    put(values, contact);
    operation.withValues(values);
    operations.add(operation.build());
    for (Metadata data: contact.getMetadata().values()) {
        values.clear();
        put(values, data);
        if (data instanceof DeletedMetadata) {
            operation = ContentProviderOperation.newDelete(Data.CONTENT_URI);
            operation.withValues(values);
            operation.withSelection(Data._ID + "=?", new String[]{Long.toString(contact.getID())});
            operations.add(operation.build());
            continue;
        }
        if (data.getID() == -1) {
            operation = ContentProviderOperation.newInsert(Data.CONTENT_URI);
        } else {
            operation = ContentProviderOperation.newUpdate(Data.CONTENT_URI);
            operation.withSelection(Data._ID + "=?", new String[]{Long.toString(data.getID())});
        }
        if (contact.getID() == -1) {
            operation.withValueBackReference(Data.RAW_CONTACT_ID, operationsStart);
            values.remove(Data.RAW_CONTACT_ID);
        } else {
            values.put(Data.RAW_CONTACT_ID, contact.getID());
        }
        operation.withValues(values);
        operations.add(operation.build());
    }
}
 
Example #27
Source File: ContactUtil.java    From haxsync with GNU General Public License v2.0 5 votes vote down vote up
public static List<HashMap<String, Object>> getMergedContacts(Context c, long rawContactID){
  	
  	
Cursor cursor = c.getContentResolver().query(RawContacts.CONTENT_URI, new String[] { RawContacts.CONTACT_ID}, RawContacts._ID +" = '" + rawContactID + "'", null, null);
ArrayList<HashMap<String, Object>> contacts = new ArrayList<HashMap<String, Object>>();

if (cursor.getCount() > 0){
	cursor.moveToFirst();
	long contactID = cursor.getLong(cursor.getColumnIndex(RawContacts.CONTACT_ID));
	Cursor c2 = c.getContentResolver().query(RawContacts.CONTENT_URI, new String[] { BaseColumns._ID, RawContacts.DISPLAY_NAME_PRIMARY, RawContacts.ACCOUNT_TYPE}, RawContacts.CONTACT_ID +" = '" + contactID + "'" + " AND " + BaseColumns._ID + " != " +rawContactID , null, null);
	while(c2.moveToNext()){
		HashMap<String, Object> contact = new HashMap<String, Object>();
		contact.put("name", c2.getString(c2.getColumnIndex(RawContacts.DISPLAY_NAME_PRIMARY)));
		contact.put("id", c2.getString(c2.getColumnIndex(BaseColumns._ID)));
		Drawable icon;
		//todo: cache this shit
		fillIcons(c);
		try{
			icon = accountIcons.get(c2.getString(c2.getColumnIndex(RawContacts.ACCOUNT_TYPE)));
		} catch (Exception e){
			fillIcons(c);
			icon = accountIcons.get(c2.getString(c2.getColumnIndex(RawContacts.ACCOUNT_TYPE)));
		}
		contact.put("icon", icon);
		contacts.add(contact);
	}
	c2.close();

}
cursor.close();
return contacts;

  }
 
Example #28
Source File: ContactUtil.java    From haxsync with GNU General Public License v2.0 5 votes vote down vote up
private static Set<Long> getRawContacts(Context c, long contactID, long rawContactID){
	HashSet<Long> ids = new HashSet<Long>();
		Cursor c2 = c.getContentResolver().query(RawContacts.CONTENT_URI, new String[] { BaseColumns._ID}, RawContacts.CONTACT_ID +" = '" + contactID + "'" + " AND " + BaseColumns._ID + " != " +rawContactID , null, null);
		while (c2.moveToNext()){
			ids.add(c2.getLong(c2.getColumnIndex(BaseColumns._ID)));
		}
		c2.close();
	return ids;
}
 
Example #29
Source File: ContactsDatabase.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
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());
}
 
Example #30
Source File: AndroidContact.java    From linphone-android with GNU General Public License v3.0 5 votes vote down vote up
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;
}