Example usage for android.provider ContactsContract CALLER_IS_SYNCADAPTER

List of usage examples for android.provider ContactsContract CALLER_IS_SYNCADAPTER

Introduction

In this page you can find the example usage for android.provider ContactsContract CALLER_IS_SYNCADAPTER.

Prototype

String CALLER_IS_SYNCADAPTER

To view the source code for android.provider ContactsContract CALLER_IS_SYNCADAPTER.

Click Source Link

Document

An optional URI parameter for insert, update, or delete queries that allows the caller to specify that it is a sync adapter.

Usage

From source file:com.rukman.emde.smsgroups.platform.GMSContactOperations.java

private static Uri addCallerIsSyncAdapterParameter(Uri uri, boolean isSyncOperation) {
    if (isSyncOperation) {
        // If we're in the middle of a real sync-adapter operation, then go ahead
        // and tell the Contacts provider that we're the sync adapter.  That
        // gives us some special permissions - like the ability to really
        // delete a contact, and the ability to clear the dirty flag.
        ///*  ww w. ja  v a  2s  . co  m*/
        // If we're not in the middle of a sync operation (for example, we just
        // locally created/edited a new contact), then we don't want to use
        // the special permissions, and the system will automagically mark
        // the contact as 'dirty' for us!
        return uri.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();
    }
    return uri;
}

From source file:com.openerp.base.res.Res_PartnerSyncHelper.java

public void syncContacts(Context context, Account account) {
    HashMap<String, SyncEntry> localContacts = new HashMap<String, SyncEntry>();
    mContentResolver = context.getContentResolver();
    int company_id = Integer.parseInt(OpenERPAccountManager.currentUser(context).getCompany_id());

    RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true")
            .build();//from w w w .j  a v  a2  s.  c o m

    // Load the local contacts
    Uri rawContactUri = RawContacts.CONTENT_URI.buildUpon()
            .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name)
            .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type).build();
    Cursor cursor = mContentResolver.query(rawContactUri, new String[] { BaseColumns._ID, SYNC1_PARTNER_ID },
            null, null, null);

    while (cursor.moveToNext()) {
        SyncEntry entry = new SyncEntry();
        entry.partner_id = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID));
        localContacts.put(cursor.getString(1), entry);
    }
    cursor.close();

    try {
        Res_PartnerDBHelper dbHelper = new Res_PartnerDBHelper(context);
        HashMap<String, Object> res = dbHelper.search(dbHelper,
                new String[] { "phone != ? ", "OR", "mobile != ? ", "OR", "email != ?" },
                new String[] { "false", "false", "false" });
        // checking if records exist?
        int total = Integer.parseInt(res.get("total").toString());

        if (total > 0) {
            @SuppressWarnings("unchecked")
            List<HashMap<String, Object>> rows = (List<HashMap<String, Object>>) res.get("records");

            for (HashMap<String, Object> row_data : rows) {

                if (!(row_data.get("company_id").toString()).equalsIgnoreCase("false")) {
                    JSONArray db_company_id = new JSONArray(row_data.get("company_id").toString());
                    String com_id = db_company_id.getJSONArray(0).getString(0).toString();

                    if (com_id.equalsIgnoreCase(String.valueOf(company_id))) {
                        String partnerID = row_data.get("id").toString();
                        String name = (row_data.get("name").toString()).replaceAll("[^\\w\\s]", "");
                        String mail = row_data.get("email").toString();
                        String number = row_data.get("phone").toString();
                        String mobile = row_data.get("mobile").toString();
                        String website = row_data.get("website").toString();
                        String street = row_data.get("street").toString();
                        String street2 = row_data.get("street2").toString();
                        String city = row_data.get("city").toString();
                        String zip = row_data.get("zip").toString();
                        String company = "OpenERP";
                        String image = row_data.get("image_small").toString();
                        if (localContacts.get(row_data.get("id").toString()) == null) {
                            addContact(context, account, partnerID, name, mail, number, mobile, website, street,
                                    street2, city, zip, company, image);
                        }
                    }
                }

            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:at.bitfire.davdroid.mirakel.resource.LocalCalendar.java

void populateAttendees(Event e) throws RemoteException {
    Uri attendeesUri = Attendees.CONTENT_URI.buildUpon()
            .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();
    @Cleanup/*from   ww  w  .  ja  v  a 2  s .  c  o  m*/
    Cursor c = providerClient.query(attendeesUri,
            new String[] { /* 0 */ Attendees.ATTENDEE_EMAIL, Attendees.ATTENDEE_NAME, Attendees.ATTENDEE_TYPE,
                    /* 3 */ Attendees.ATTENDEE_RELATIONSHIP, Attendees.STATUS },
            Attendees.EVENT_ID + "=?", new String[] { String.valueOf(e.getLocalID()) }, null);
    while (c != null && c.moveToNext()) {
        try {
            Attendee attendee = new Attendee(new URI("mailto", c.getString(0), null));
            ParameterList params = attendee.getParameters();

            String cn = c.getString(1);
            if (cn != null)
                params.add(new Cn(cn));

            // type
            int type = c.getInt(2);
            params.add((type == Attendees.TYPE_RESOURCE) ? CuType.RESOURCE : CuType.INDIVIDUAL);

            // role
            int relationship = c.getInt(3);
            switch (relationship) {
            case Attendees.RELATIONSHIP_ORGANIZER:
                params.add(Role.CHAIR);
                break;
            case Attendees.RELATIONSHIP_ATTENDEE:
            case Attendees.RELATIONSHIP_PERFORMER:
            case Attendees.RELATIONSHIP_SPEAKER:
                params.add((type == Attendees.TYPE_REQUIRED) ? Role.REQ_PARTICIPANT : Role.OPT_PARTICIPANT);
                break;
            case Attendees.RELATIONSHIP_NONE:
                params.add(Role.NON_PARTICIPANT);
            }

            // status
            switch (c.getInt(4)) {
            case Attendees.ATTENDEE_STATUS_INVITED:
                params.add(PartStat.NEEDS_ACTION);
                break;
            case Attendees.ATTENDEE_STATUS_ACCEPTED:
                params.add(PartStat.ACCEPTED);
                break;
            case Attendees.ATTENDEE_STATUS_DECLINED:
                params.add(PartStat.DECLINED);
                break;
            case Attendees.ATTENDEE_STATUS_TENTATIVE:
                params.add(PartStat.TENTATIVE);
                break;
            }

            e.addAttendee(attendee);
        } catch (URISyntaxException ex) {
            Log.e(TAG, "Couldn't parse attendee information, ignoring", ex);
        }
    }
}

From source file:com.example.jumpnote.android.SyncAdapter.java

private static Uri addCallerIsSyncAdapterParameter(Uri uri) {
    return uri.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();
}

From source file:at.bitfire.davdroid.mirakel.resource.LocalCalendar.java

void populateReminders(Event e) throws RemoteException {
    // reminders/*  w w  w  . ja  va 2 s  .c o  m*/
    Uri remindersUri = Reminders.CONTENT_URI.buildUpon()
            .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();
    @Cleanup
    Cursor c = providerClient.query(remindersUri, new String[] { /* 0 */ Reminders.MINUTES, Reminders.METHOD },
            Reminders.EVENT_ID + "=?", new String[] { String.valueOf(e.getLocalID()) }, null);
    while (c != null && c.moveToNext()) {
        VAlarm alarm = new VAlarm(new Dur(0, 0, -c.getInt(0), 0));

        PropertyList props = alarm.getProperties();
        switch (c.getInt(1)) {
        /*case Reminders.METHOD_EMAIL:
           props.add(Action.EMAIL);
           break;*/
        default:
            props.add(Action.DISPLAY);
            props.add(new Description(e.getSummary()));
        }
        e.addAlarm(alarm);
    }
}

From source file:org.exfio.csyncdroid.resource.LocalCalendar.java

void populateAttendees(Event e) throws RemoteException {
    Uri attendeesUri = Attendees.CONTENT_URI.buildUpon()
            .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();
    @Cleanup/*  w  w w  .ja va2 s  .c om*/
    Cursor c = providerClient.query(attendeesUri,
            new String[] { /* 0 */ Attendees.ATTENDEE_EMAIL, Attendees.ATTENDEE_NAME, Attendees.ATTENDEE_TYPE,
                    /* 3 */ Attendees.ATTENDEE_RELATIONSHIP, Attendees.STATUS },
            Attendees.EVENT_ID + "=?", new String[] { String.valueOf(e.getLocalID()) }, null);

    while (c != null && c.moveToNext()) {

        Attendee attendee = new Attendee(c.getString(1), c.getString(0));

        // type
        int type = c.getInt(2);
        attendee.setParameter("TYPE", (type == Attendees.TYPE_RESOURCE) ? "RESOURCE" : "NONE");

        // role
        int relationship = c.getInt(3);
        switch (relationship) {
        case Attendees.RELATIONSHIP_ORGANIZER:
            attendee.setRole(Role.CHAIR);
            break;
        case Attendees.RELATIONSHIP_ATTENDEE:
        case Attendees.RELATIONSHIP_PERFORMER:
        case Attendees.RELATIONSHIP_SPEAKER:
            attendee.setRole(Role.ATTENDEE);
            break;
        case Attendees.RELATIONSHIP_NONE:
            //No role
            break;
        default:
            //Ignore
        }

        // status
        switch (c.getInt(4)) {
        case Attendees.ATTENDEE_STATUS_INVITED:
            attendee.setParticipationStatus(ParticipationStatus.NEEDS_ACTION);
            break;
        case Attendees.ATTENDEE_STATUS_ACCEPTED:
            attendee.setParticipationStatus(ParticipationStatus.ACCEPTED);
            break;
        case Attendees.ATTENDEE_STATUS_DECLINED:
            attendee.setParticipationStatus(ParticipationStatus.DECLINED);
            break;
        case Attendees.ATTENDEE_STATUS_TENTATIVE:
            attendee.setParticipationStatus(ParticipationStatus.TENTATIVE);
            break;
        default:
            //Ignore
        }

        e.addAttendee(attendee);
    }
}

From source file:org.exfio.csyncdroid.resource.LocalCalendar.java

void populateReminders(Event e) throws RemoteException {
    // reminders//  w ww.  j a  v a  2 s .co  m
    Uri remindersUri = Reminders.CONTENT_URI.buildUpon()
            .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();
    @Cleanup
    Cursor c = providerClient.query(remindersUri, new String[] { /* 0 */ Reminders.MINUTES, Reminders.METHOD },
            Reminders.EVENT_ID + "=?", new String[] { String.valueOf(e.getLocalID()) }, null);
    while (c != null && c.moveToNext()) {
        //Duration duration = new Duration.Builder().prior(true).minutes(c.getInt(0)).build();
        Duration duration = new Duration.Builder().minutes(c.getInt(0)).build();
        Trigger trigger = new Trigger(duration, Related.START);
        VAlarm alarm = VAlarm.display(trigger, e.getSummary());
        e.addAlarm(alarm);
    }
}

From source file:org.sufficientlysecure.keychain.util.ContactHelper.java

/**
 * deletes a raw contact from the main profile table ("me" contact)
 * http://developer.android.com/reference/android/provider/ContactsContract.Profile.html
 *
 * @return number of rows deleted//from   w w w .j a va2s .  c o m
 */
private int deleteMainProfileRawContactByMasterKeyId(long masterKeyId) {
    // CALLER_IS_SYNCADAPTER allows us to actually wipe the RawContact from the device, otherwise
    // would be just flagged for deletion
    Uri deleteUri = ContactsContract.Profile.CONTENT_RAW_CONTACTS_URI.buildUpon()
            .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();

    return mContentResolver.delete(
            deleteUri, ContactsContract.RawContacts.ACCOUNT_TYPE + "=? AND "
                    + ContactsContract.RawContacts.SOURCE_ID + "=?",
            new String[] { Constants.ACCOUNT_TYPE, Long.toString(masterKeyId) });
}

From source file:org.sufficientlysecure.keychain.util.ContactHelper.java

/**
 * deletes all raw contact entries in the "me" contact flagged for deletion ('hidden'),
 * presumably by the user//from  ww w  .j a  v  a2  s  . c om
 *
 * @return number of raw contacts deleted
 */
private int deleteFlaggedMainProfileRawContacts() {
    // CALLER_IS_SYNCADAPTER allows us to actually wipe the RawContact from the device, otherwise
    // would be just flagged for deletion
    Uri deleteUri = ContactsContract.Profile.CONTENT_RAW_CONTACTS_URI.buildUpon()
            .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();

    return mContentResolver.delete(deleteUri,
            ContactsContract.RawContacts.ACCOUNT_TYPE + "=? AND " + ContactsContract.RawContacts.DELETED + "=?",
            new String[] { Constants.ACCOUNT_TYPE, "1" });
}

From source file:org.sufficientlysecure.keychain.util.ContactHelper.java

/**
 * Delete all raw contacts associated to OpenKeychain, including those from "me" contact
 * defined by ContactsContract.Profile/*from   w  ww  . j  a  v  a 2 s  .c  om*/
 *
 * @return number of rows deleted
 */
public int deleteAllContacts() {
    // CALLER_IS_SYNCADAPTER allows us to actually wipe the RawContact from the device, otherwise
    // would be just flagged for deletion
    Uri deleteUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon()
            .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();

    Log.d(Constants.TAG, "Deleting all raw contacts associated to OK...");
    int delete = mContentResolver.delete(deleteUri, ContactsContract.RawContacts.ACCOUNT_TYPE + "=?",
            new String[] { Constants.ACCOUNT_TYPE });

    Uri mainProfileDeleteUri = ContactsContract.Profile.CONTENT_RAW_CONTACTS_URI.buildUpon()
            .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();

    delete += mContentResolver.delete(mainProfileDeleteUri, ContactsContract.RawContacts.ACCOUNT_TYPE + "=?",
            new String[] { Constants.ACCOUNT_TYPE });

    return delete;
}