Contacts, New Questions

satya - 1/2/2015, 1:14:28 PM

adding a contact to a device account in android

adding a contact to a device account in android

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

satya - 1/2/2015, 1:29:12 PM

ContactsProvider2.java

ContactsProvider2.java

Search for: ContactsProvider2.java

satya - 1/2/2015, 1:33:37 PM

resolveAccount null account android

resolveAccount null account android

Search for: resolveAccount null account android

satya - 1/2/2015, 1:36:52 PM

device AccountWithDataSet

device AccountWithDataSet

Search for: device AccountWithDataSet

satya - 1/3/2015, 9:11:38 AM

What happens if I add a contact when there is no account established

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

satya - 1/3/2015, 9:12:51 AM

You can also seem to be able to add a contact with invalid account name and type

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

satya - 1/3/2015, 9:13:57 AM

How do I see such a contact when it has no parent account

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.

satya - 1/3/2015, 9:19:53 AM

Here is what the resolveAccount source code suggests in comments


/**
     * 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}.
     */

satya - 1/5/2015, 10:33:41 AM

Read about the SyncAPI here

Read about the SyncAPI here

satya - 1/5/2015, 10:34:36 AM

New Contracts


ContactsContract.StreamItems
ContactsContract.StreamItemPhotos

satya - 1/5/2015, 10:38:48 AM

So What are Social Streams?

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

satya - 1/5/2015, 10:51:41 AM

A group of contacts is allowed and discussed here

A group of contacts is allowed and discussed here

satya - 1/5/2015, 10:54:47 AM

How are streams used

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

satya - 1/6/2015, 10:00:37 AM

In howmany way can you reuse the contacts UI

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.

satya - 1/6/2015, 10:02:36 AM

Getting access to content providers via intents is discussed here

Getting access to content providers via intents is discussed here

satya - 1/6/2015, 10:04:13 AM

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

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

satya - 1/6/2015, 10:04:55 AM

There are more refined definitions for creating contacts through intents

There are more refined definitions for creating contacts through intents

satya - 1/6/2015, 10:11:07 AM

Two kinds of 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

satya - 1/6/2015, 10:13:32 AM

Example of fired intents


INVITE_CONTACT
SEARCH_SUGGESTION_CLICKED
SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED
SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED
CONTACTS_DATABASE_CREATED

satya - 1/6/2015, 10:14:31 AM

Example of invoking UI intents


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

satya - 1/6/2015, 10:16:39 AM

ACTION_PICK: Pick a contact from a list

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.

satya - 1/6/2015, 10:17:26 AM

Insert.ACTION: Invokes a create contact activity

Insert.ACTION: Invokes a create contact activity

satya - 1/6/2015, 10:17:52 AM

ACTION_EDIT or ACTION_EDIT_OR_CREATE

ACTION_EDIT or ACTION_EDIT_OR_CREATE

satya - 1/6/2015, 10:21:53 AM

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

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

satya - 1/6/2015, 10:23:38 AM

Approach is this

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

satya - 1/6/2015, 10:41:05 AM

SEARCH_SUGGESTION_CLICKED

SEARCH_SUGGESTION_CLICKED

Search for: SEARCH_SUGGESTION_CLICKED

satya - 1/6/2015, 10:46:16 AM

android.provider.Contacts.SEARCH_SUGGESTION_CLICKED

android.provider.Contacts.SEARCH_SUGGESTION_CLICKED

Search for: android.provider.Contacts.SEARCH_SUGGESTION_CLICKED

satya - 1/6/2015, 10:54:58 AM

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

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

satya - 1/6/2015, 11:48:32 AM

SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED

SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED

Search for: SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED

satya - 1/6/2015, 11:48:43 AM

SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED

SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED

Search for: SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED

satya - 1/6/2015, 11:52:27 AM

Android Contact Provider as a Search Provider

Android Contact Provider as a Search Provider

Search for: Android Contact Provider as a Search Provider

satya - 1/6/2015, 11:54:31 AM

ContactProvider2.java

ContactProvider2.java

Search for: ContactProvider2.java

satya - 1/6/2015, 11:55:49 AM

ContactsProvider2.java

ContactsProvider2.java

Search for: ContactsProvider2.java

satya - 1/6/2015, 12:06:13 PM

GlobalSearchSupport.java

GlobalSearchSupport.java

Search for: GlobalSearchSupport.java

satya - 1/6/2015, 12:33:31 PM

Columns1


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,
    };

satya - 1/6/2015, 12:34:17 PM

Contacts Columns


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;

satya - 1/6/2015, 12:46:16 PM

Contact Provider Suggestion Cursor Columns

Contact Provider Suggestion Cursor Columns

Search for: Contact Provider Suggestion Cursor Columns

satya - 1/6/2015, 4:45:41 PM

You will find search configuration xml params

You will find search configuration xml params

satya - 1/6/2015, 4:46:26 PM

Here are my notes on previous search research

Here are my notes on previous search research

satya - 1/6/2015, 5:54:48 PM

OK most likely explanation for SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED

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....

satya - 1/7/2015, 11:20:44 AM

Key classes in understanding how Contact Provider fulfills its search contracts


Package: com.android.providers.contacts

//this is the key class
GlobalSearchSupport.java 

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

satya - 1/7/2015, 11:24:33 AM

Some notes on contact provider as a search provider

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.

satya - 1/7/2015, 11:28:44 AM

An example for contact provider search suggest intents


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;
}

satya - 1/7/2015, 11:40:04 AM

Key references for using Contact provider as a search provider

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

satya - 2/27/2015, 3:16:35 PM

Why is ContactsContract.StreamItems deprecated?

Why is ContactsContract.StreamItems deprecated?

Search for: Why is ContactsContract.StreamItems deprecated?