Example usage for android.provider Contacts CONTENT_URI

List of usage examples for android.provider Contacts CONTENT_URI

Introduction

In this page you can find the example usage for android.provider Contacts CONTENT_URI.

Prototype

Uri CONTENT_URI

To view the source code for android.provider Contacts CONTENT_URI.

Click Source Link

Document

The content:// style URL for this provider

Usage

From source file:Main.java

/**
 * @brief      Get the add tel intent/*from  www. j  a v  a2  s  .co m*/
 *
 * @par        Sync (or) Async:
 * This is a Synchronous function.
 *
 * @param [IN] telNumber    Tel number.\n
 * 
 * @return     
 *
 * @author     daiping.zhao
 * @since      1.0.0.0
 * @version    1.0.0.0
 * @par        Prospective Clients:
 * External Classes
 */
public static Intent doAddTelContact(String telNumber) {
    Intent newIntent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
    newIntent.putExtra(Intents.Insert.PHONE, telNumber);
    return newIntent;
}

From source file:Main.java

/**
 * @brief      Get the intent to insert email into contact
 *
 * @par        Sync (or) Async:/*from ww  w .  j a v a 2 s  .c  o m*/
 * This is a Synchronous function.
 *
 * @param [IN] email    Email address.\n
 * 
 * @return     
 *
 * @author     daiping.zhao
 * @since      1.0.0.0
 * @version    1.0.0.0
 * @par        Prospective Clients:
 * External Classes
 */
public static Intent doAddEmailToContact(String email) {
    Intent newIntent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
    newIntent.putExtra(Intents.Insert.EMAIL, email);
    return newIntent;
}

From source file:Main.java

/**
 * @brief      Get the intent to add email address to existed contact.
 *
 * @par        Sync (or) Async:/*from   w  ww . j ava 2 s.c o m*/
 * This is a Synchronous function.
 *
 * @param [IN] email    email address.\n
 * 
 * @return     
 *
 * @author     daiping.zhao
 * @since      1.0.0.0
 * @version    1.0.0.0
 * @par        Prospective Clients:
 * External Classes
 */
public static Intent doAddEmaliToExistContact(String email) {
    Intent newIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT, Contacts.CONTENT_URI);
    newIntent.setType(Contacts.CONTENT_ITEM_TYPE);
    newIntent.putExtra(Intents.Insert.EMAIL, email);
    return newIntent;
}

From source file:Main.java

/**
 * @brief      Get the intent to add telephone number into contact. 
 *
 * @par        Sync (or) Async://from   w w w . j  a v  a 2  s . c o m
 * This is a Synchronous function.
 *
 * @param [IN] telNumber    Telephone number.\n
 * 
 * @return     
 *
 * @author     daiping.zhao
 * @since      1.0.0.0
 * @version    1.0.0.0
 * @par        Prospective Clients:
 * External Classes
 */
public static Intent doAddTelToExistContact(String telNumber) {
    Intent newIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT, Contacts.CONTENT_URI);
    newIntent.setType(Contacts.CONTENT_ITEM_TYPE);
    newIntent.putExtra(Intents.Insert.PHONE, telNumber);
    return newIntent;
}

From source file:org.apache.cordova.contactVcardpicker.ContactVcardPicker.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    this.callbackContext = callbackContext;
    if (action.equals("getContactVcard")) {
        Log.d("customPlugin", " getContactVcard ");

        Runnable getContactVcard = new Runnable() {

            @Override//from ww w.  j  av a2s .c o m
            public void run() {
                Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,
                        ContactsContract.Contacts.CONTENT_URI);
                cordova.setActivityResultCallback(ContactVcardPicker.this);
                cordova.getActivity().startActivityForResult(contactPickerIntent, 5);
            }
        };
        this.cordova.getActivity().runOnUiThread(getContactVcard);
        return true;
    } else {
        return false;
    }
}

From source file:org.apache.cordova.plugin.ExportVCFsToFilePlugin.java

private String getVcardString(String fileName, String fileExtension) throws IOException {
    contactsSet = new HashSet<String>();
    cursor = this.cordova.getActivity().getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null,
            null, null, null);//from   ww w.ja v a 2 s  .  co  m
    if (cursor != null && cursor.getCount() > 0) {
        int i;
        File outputDir = this.cordova.getActivity().getCacheDir();
        String fullFilePath = outputDir.getAbsolutePath() + "/" + fileName + "." + fileExtension;
        FileOutputStream mFileOutputStream = new FileOutputStream(fullFilePath, false);

        cursor.moveToFirst();

        for (i = 0; i < cursor.getCount(); i++) {
            Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI,
                    cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY)));
            AssetFileDescriptor fd;
            try {
                fd = this.cordova.getActivity().getContentResolver().openAssetFileDescriptor(uri, "r");
                FileInputStream fis = fd.createInputStream();
                byte[] buf = new byte[(int) fd.getDeclaredLength()];
                fis.read(buf);
                contactsSet.add(new String(buf));
            } catch (Exception e1) {
            }
            cursor.moveToNext();
        }
        Iterator it = contactsSet.iterator();
        while (it.hasNext()) {
            try {
                mFileOutputStream.write(it.next().toString().getBytes());
            } catch (IOException e) {
            }
        }
        mFileOutputStream.close();
        cursor.close();
        return fullFilePath;
    } else {
        Log.d("TAG", "No Contacts in Your Phone");
        return "";
    }
}

From source file:android.syncml.pim.vcard.VCardDataBuilder.java

private void tryGetOriginalProvider() {
    final ContentResolver resolver = mContentResolver;

    if ((mMyContactsGroupId = Contacts.People.tryGetMyContactsGroupId(resolver)) == 0) {
        Log.e(LOG_TAG, "Could not get group id of MyContact");
        return;//  ww  w. j  a va2  s .  c  om
    }

    IContentProvider iProviderForName = resolver.acquireProvider(Contacts.CONTENT_URI);
    ContentProvider contentProvider = ContentProvider.coerceToLocalContentProvider(iProviderForName);
    if (contentProvider == null) {
        Log.e(LOG_TAG, "Fail to get ContentProvider object.");
        return;
    }

    if (!(contentProvider instanceof AbstractSyncableContentProvider)) {
        Log.e(LOG_TAG, "Acquired ContentProvider object is not AbstractSyncableContentProvider.");
        return;
    }

    mProvider = (AbstractSyncableContentProvider) contentProvider;
}

From source file:com.android.providers.contacts.ContactsSyncAdapter.java

@Override
public void onSyncEnding(SyncContext context, boolean success) {
    final ContentResolver cr = getContext().getContentResolver();

    if (success && mPerformedGetServerDiffs && !mSyncCanceled) {
        Cursor cursor = cr.query(Photos.CONTENT_URI,
                new String[] { Photos._SYNC_ID, Photos._SYNC_VERSION, Photos.PERSON_ID,
                        Photos.DOWNLOAD_REQUIRED },
                "" + "_sync_account=? AND download_required != 0", new String[] { getAccount() }, null);
        try {//  w w  w.  ja v  a 2s  . com
            if (cursor.getCount() != 0) {
                Bundle extras = new Bundle();
                extras.putString(ContentResolver.SYNC_EXTRAS_ACCOUNT, getAccount());
                extras.putBoolean(ContentResolver.SYNC_EXTRAS_FORCE, mSyncForced);
                extras.putString("feed", ContactsSyncAdapter.getPhotosFeedForAccount(getAccount()));
                getContext().getContentResolver().startSync(Contacts.CONTENT_URI, extras);
            }
        } finally {
            cursor.close();
        }
    }

    super.onSyncEnding(context, success);
}

From source file:com.android.providers.contacts.ContactsSyncAdapter.java

public static void updateSubscribedFeeds(ContentResolver cr, String account) {
    Set<String> feedsToSync = Sets.newHashSet();
    feedsToSync.add(getGroupsFeedForAccount(account));
    addContactsFeedsToSync(cr, account, feedsToSync);

    Cursor c = SubscribedFeeds.Feeds.query(cr, sSubscriptionProjection,
            SubscribedFeeds.Feeds.AUTHORITY + "=? AND " + SubscribedFeeds.Feeds._SYNC_ACCOUNT + "=?",
            new String[] { Contacts.AUTHORITY, account }, null);
    try {//  w  ww .  j  ava 2s  .  co  m
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "scanning over subscriptions with authority " + Contacts.AUTHORITY + " and account "
                    + account);
        }
        c.moveToNext();
        while (!c.isAfterLast()) {
            String feedInCursor = c.getString(1);
            if (feedsToSync.contains(feedInCursor)) {
                feedsToSync.remove(feedInCursor);
                c.moveToNext();
            } else {
                c.deleteRow();
            }
        }
        c.commitUpdates();
    } finally {
        c.close();
    }

    // any feeds remaining in feedsToSync need a subscription
    for (String feed : feedsToSync) {
        SubscribedFeeds.addFeed(cr, feed, account, Contacts.AUTHORITY, ContactsClient.SERVICE);

        // request a sync of this feed
        Bundle extras = new Bundle();
        extras.putString(ContentResolver.SYNC_EXTRAS_ACCOUNT, account);
        extras.putString("feed", feed);
        cr.startSync(Contacts.CONTENT_URI, extras);
    }
}