Contacts, New Questions

adding a contact to a device account in android

Search for: adding a contact to a device account in android

ContactsProvider2.java

Search for: ContactsProvider2.java

resolveAccount null account android

Search for: resolveAccount null account android

device AccountWithDataSet

Search for: device AccountWithDataSet

The contact gets added without an error. The contact will be listed as phone only or device only.

When i tested with an invalid account type and account name it seem to add it too.

When I examine the contact in the contacts UI provided by Android it seem to assume it is the device only or phone only contact in both cases.


/**
     * If account is non-null then store it in the values. If the account is
     * already specified in the values then it must be consistent with the
     * account, if it is non-null.
     *
     * @param uri Current {@link Uri} being operated on.
     * @param values {@link ContentValues} to read and possibly update.
     * @throws IllegalArgumentException when only one of
     *             {@link RawContacts#ACCOUNT_NAME} or
     *             {@link RawContacts#ACCOUNT_TYPE} is specified, leaving the
     *             other undefined.
     * @throws IllegalArgumentException when {@link RawContacts#ACCOUNT_NAME}
     *             and {@link RawContacts#ACCOUNT_TYPE} are inconsistent between
     *             the given {@link Uri} and {@link ContentValues}.
     */

Read about the SyncAPI here


ContactsContract.StreamItems
ContactsContract.StreamItemPhotos

A raw contact or person could post their constant status updates and some photos associated with that post.

These can be picked up by sync adapters to store in these two tables

One table is for the text of the post

The second table points to a series of photos tied to that post

A group of contacts is allowed and discussed here

One obvious way is to sync the user activity between the device and the social servers using the frequent synching process

You can also register for events when the user accesses a local contact either to view, update etc. In that case you can fire of the synching on a case by case basis to save time and bandwidth

You can also invoke application activities by providing an invite features while in the contacts application

Pick a contact from a list and have it returned to your app for further work.

Edit an existing contact's data.

Insert a new raw contact for any of their accounts.

Delete a contact or contacts data.

Getting access to content providers via intents is discussed here

Here is a list of intents published for a contact provider application

There are more refined definitions for creating contacts through intents

Intents that the content provider can fire on certain events taking place

Intents that external applications can send to invoke the UI of the content provider


INVITE_CONTACT
SEARCH_SUGGESTION_CLICKED
SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED
SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED
CONTACTS_DATABASE_CREATED

ATTACH_IMAGE -- to a contact
SHOW_OR_CREATE_CONTACT -- To show a contact, or create one

Contacts.CONTENT_URI, which displays a list of contacts.

Phone.CONTENT_URI, which displays a list of phone numbers for a raw contact.

StructuredPostal.CONTENT_URI, which displays a list of postal addresses for a raw contact.

Email.CONTENT_URI, which displays a list of email addresses for a raw contact.

Insert.ACTION: Invokes a create contact activity

ACTION_EDIT or ACTION_EDIT_OR_CREATE

See the following to see how to send an insert intent with various data values

Set the action to insert

Set the mime type raw contact mime type

Send the data values in a list of key/value pairs (content values)

In each data row specify the mime type

Send the intent

The UI will showup with the fields pre-filled

SEARCH_SUGGESTION_CLICKED

Search for: SEARCH_SUGGESTION_CLICKED

android.provider.Contacts.SEARCH_SUGGESTION_CLICKED

Search for: android.provider.Contacts.SEARCH_SUGGESTION_CLICKED

You can see here in this tutorial how these events suggest events are used

SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED

Search for: SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED

SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED

Search for: SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED

Android Contact Provider as a Search Provider

Search for: Android Contact Provider as a Search Provider

ContactProvider2.java

Search for: ContactProvider2.java

ContactsProvider2.java

Search for: ContactsProvider2.java

GlobalSearchSupport.java

Search for: GlobalSearchSupport.java


private static final String[] SEARCH_SUGGESTIONS_COLUMNS = {
            "_id",
            SearchManager.SUGGEST_COLUMN_TEXT_1,
            SearchManager.SUGGEST_COLUMN_TEXT_2,
            SearchManager.SUGGEST_COLUMN_ICON_1,
            SearchManager.SUGGEST_COLUMN_ICON_2,
            SearchManager.SUGGEST_COLUMN_INTENT_DATA,
            SearchManager.SUGGEST_COLUMN_INTENT_ACTION,
            SearchManager.SUGGEST_COLUMN_SHORTCUT_ID,
            SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA,
            SearchManager.SUGGEST_COLUMN_LAST_ACCESS_HINT,
    };

private static class SearchSuggestion {
        long contactId;
        String photoUri;
        String lookupKey;
        int presence = -1;
        String text1;
        String text2;
        String icon1;
        String icon2;
        String intentData;
        String intentAction;
        String filter;
        String lastAccessTime;

Contact Provider Suggestion Cursor Columns

Search for: Contact Provider Suggestion Cursor Columns

You will find search configuration xml params

Here are my notes on previous search research

Note that this is speculation as I havent' tried it. But it is provable with a simple app

When a valid phone number is typed into the search box of a contact suggestions the contact provider may insert two suggestions

One suggestion is to create a contact with that number

Another suggestion is to dial that number

These suggestions will generate intent actions that are specific to them which are these two listed here.

In your search target activity you can look for these intent actions and fire off a start activity with the intent data portion pointing to the telephone number given

Possible....


Package: com.android.providers.contacts

//this is the key class
GlobalSearchSupport.java 

//honors the basic Query method with the SEARCH SUGGEST uri
ContactProvider2.java 

Any content provider is a search provider as well as long as it recognizes the SEARCH specific uri that is passed to its query method.

A content provider typically sets the data portion of the intent for each suggestion when it is clicked with the content uri which points to the real data cursor

A content provier may also provide varied intent actions for each suggestion that is returned

That means the search activity responding to the search suggestion must have a case statement to understand each expected intent action by looking at the documentation of the content provider

What is to be done in each of the intent actions may be different and this can be understood only by understanding the intent action that is stipulated by the content provider.


case SEARCH_SUGGESTION_CLICKED_CONTACT: {
  //Just read the details of the contact
  //Do whatever you have searched this contact for
  break;
}
case SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED: {
  //User has chosen from the list of suggestions to call the number
  //data uri points to the structure "tel:some-number"
  //Invoke the dialer using its intent;
  //Pass the data uri as data for that intent
  break;
}
case SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED: {
  //User has chosen from the list of suggestions to create a contact for the number
  //data uri points to the structure "tel:some-number"
  //Invoke the create activity using its intent;
  //Pass the data uri as data for that intent
  break;
}

My notes on search

Documentation on Search from Google

Search.xml reference

My free chapter on writing custom Search providers

ContactProvider2.java

GlobalSearchSupport.java

My Research notes on using Contact Provider as a search provider

Android SDKC docs on Contact Provider API

Why is ContactsContract.StreamItems deprecated?

Search for: Why is ContactsContract.StreamItems deprecated?