ShowOrCreateActivitypublic final class ShowOrCreateActivity extends android.app.Activity Handle several edge cases around showing or possibly creating contacts in
connected with a specific E-mail address or phone number. Will search based
on incoming {@link Intent#getData()} as described by
{@link Intents#SHOW_OR_CREATE_CONTACT}.
- If no matching contacts found, will prompt user with dialog to add to a
contact, then will use {@link Intent#ACTION_INSERT_OR_EDIT} to let create new
contact or edit new data into an existing one.
- If one matching contact found, directly show {@link Intent#ACTION_VIEW}
that specific contact.
- If more than one matching found, show list of matching contacts using
{@link Intent#ACTION_SEARCH}.
|
Fields Summary |
---|
static final String | TAG | static final boolean | LOGD | static final String[] | PHONES_PROJECTION | static final String[] | PEOPLE_PROJECTION | static final String | SCHEME_MAILTO | static final String | SCHEME_TEL | static final int | PERSON_ID_INDEX | static final String | QUERY_KIND_EMAIL_OR_IMQuery clause to filter {@link ContactMethods#CONTENT_URI} to only search
{@link Contacts#KIND_EMAIL} or {@link Contacts#KIND_IM}. | static final int | QUERY_TOKEN | private QueryHandler | mQueryHandler |
Methods Summary |
---|
protected void | onCreate(android.os.Bundle icicle)
super.onCreate(icicle);
// Create handler if doesn't exist, otherwise cancel any running
if (mQueryHandler == null) {
mQueryHandler = new QueryHandler(this);
} else {
mQueryHandler.cancelOperation(QUERY_TOKEN);
}
final Intent intent = getIntent();
final Uri data = intent.getData();
// Unpack scheme and target data from intent
String scheme = null;
String ssp = null;
if (data != null) {
scheme = data.getScheme();
ssp = data.getSchemeSpecificPart();
}
// Build set of extras for possible use when creating contact
Bundle createExtras = new Bundle();
Bundle originalExtras = intent.getExtras();
if (originalExtras != null) {
createExtras.putAll(originalExtras);
}
mQueryHandler.setCreateExtras(createExtras);
// Read possible extra with specific title
String createDescrip = intent.getStringExtra(Intents.EXTRA_CREATE_DESCRIPTION);
if (createDescrip == null) {
createDescrip = ssp;
}
mQueryHandler.setCreateDescription(createDescrip);
// Allow caller to bypass dialog prompt
boolean createForce = intent.getBooleanExtra(Intents.EXTRA_FORCE_CREATE, false);
mQueryHandler.setCreateForce(createForce);
// Handle specific query request
if (SCHEME_MAILTO.equals(scheme)) {
createExtras.putString(Intents.Insert.EMAIL, ssp);
Uri uri = Uri.withAppendedPath(People.WITH_EMAIL_OR_IM_FILTER_URI, Uri.encode(ssp));
mQueryHandler.startQuery(QUERY_TOKEN, null, uri,
PEOPLE_PROJECTION, null, null, null);
} else if (SCHEME_TEL.equals(scheme)) {
createExtras.putString(Intents.Insert.PHONE, ssp);
mQueryHandler.startQuery(QUERY_TOKEN, null,
Uri.withAppendedPath(Phones.CONTENT_FILTER_URL, ssp),
PHONES_PROJECTION, null, null, null);
} else {
Log.w(TAG, "Invalid intent:" + getIntent());
finish();
}
| protected void | onStop()
super.onStop();
if (mQueryHandler != null) {
mQueryHandler.cancelOperation(QUERY_TOKEN);
}
|
|