@Override protected RawContactDeltaList doInBackground(Intent... params) { final Intent intent = params[0]; final ContentResolver resolver = activityTarget.getContentResolver(); // Handle both legacy and new authorities final Uri data = intent.getData(); final String authority = data.getAuthority(); final String mimeType = intent.resolveType(resolver); mSelection = "0"; String selectionArg = null; if (ContactsContract.AUTHORITY.equals(authority)) { if (Contacts.CONTENT_ITEM_TYPE.equals(mimeType)) { // Handle selected aggregate final long contactId = ContentUris.parseId(data); selectionArg = String.valueOf(contactId); mSelection = RawContacts.CONTACT_ID + "=?"; } else if (RawContacts.CONTENT_ITEM_TYPE.equals(mimeType)) { final long rawContactId = ContentUris.parseId(data); final long contactId = queryForContactId(resolver, rawContactId); selectionArg = String.valueOf(contactId); mSelection = RawContacts.CONTACT_ID + "=?"; } } else if (android.provider.Contacts.AUTHORITY.equals(authority)) { final long rawContactId = ContentUris.parseId(data); selectionArg = String.valueOf(rawContactId); mSelection = Data.RAW_CONTACT_ID + "=?"; } // Note that this query does not need to concern itself with whether the contact is // the user's profile, since the profile does not show up in the picker. return RawContactDeltaList.fromQuery( RawContactsEntity.CONTENT_URI, activityTarget.getContentResolver(), mSelection, new String[] {selectionArg}, null); }
public ContactsRequest resolveIntent(Intent intent) { ContactsRequest request = new ContactsRequest(); String action = intent.getAction(); Log.i(TAG, "Called with action: " + action); if (UI.LIST_DEFAULT.equals(action)) { request.setActionCode(ContactsRequest.ACTION_DEFAULT); } else if (UI.LIST_ALL_CONTACTS_ACTION.equals(action)) { request.setActionCode(ContactsRequest.ACTION_ALL_CONTACTS); } else if (UI.LIST_CONTACTS_WITH_PHONES_ACTION.equals(action)) { request.setActionCode(ContactsRequest.ACTION_CONTACTS_WITH_PHONES); } else if (UI.LIST_STARRED_ACTION.equals(action)) { request.setActionCode(ContactsRequest.ACTION_STARRED); } else if (UI.LIST_FREQUENT_ACTION.equals(action)) { request.setActionCode(ContactsRequest.ACTION_FREQUENT); } else if (UI.LIST_STREQUENT_ACTION.equals(action)) { request.setActionCode(ContactsRequest.ACTION_STREQUENT); } else if (UI.LIST_GROUP_ACTION.equals(action)) { request.setActionCode(ContactsRequest.ACTION_GROUP); // We no longer support UI.GROUP_NAME_EXTRA_KEY } else if (Intent.ACTION_PICK.equals(action)) { final String resolvedType = intent.resolveType(mContext); if (Contacts.CONTENT_TYPE.equals(resolvedType)) { request.setActionCode(ContactsRequest.ACTION_PICK_CONTACT); } else if (People.CONTENT_TYPE.equals(resolvedType)) { request.setActionCode(ContactsRequest.ACTION_PICK_CONTACT); request.setLegacyCompatibilityMode(true); } else if (Phone.CONTENT_TYPE.equals(resolvedType)) { request.setActionCode(ContactsRequest.ACTION_PICK_PHONE); } else if (Phones.CONTENT_TYPE.equals(resolvedType)) { request.setActionCode(ContactsRequest.ACTION_PICK_PHONE); request.setLegacyCompatibilityMode(true); } else if (StructuredPostal.CONTENT_TYPE.equals(resolvedType)) { request.setActionCode(ContactsRequest.ACTION_PICK_POSTAL); } else if (ContactMethods.CONTENT_POSTAL_TYPE.equals(resolvedType)) { request.setActionCode(ContactsRequest.ACTION_PICK_POSTAL); request.setLegacyCompatibilityMode(true); } else if (Email.CONTENT_TYPE.equals(resolvedType)) { request.setActionCode(ContactsRequest.ACTION_PICK_EMAIL); } } else if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) { String component = intent.getComponent().getClassName(); if (component.equals("alias.DialShortcut")) { request.setActionCode(ContactsRequest.ACTION_CREATE_SHORTCUT_CALL); } else if (component.equals("alias.MessageShortcut")) { request.setActionCode(ContactsRequest.ACTION_CREATE_SHORTCUT_SMS); } else { request.setActionCode(ContactsRequest.ACTION_CREATE_SHORTCUT_CONTACT); } } else if (Intent.ACTION_GET_CONTENT.equals(action)) { String type = intent.getType(); if (Contacts.CONTENT_ITEM_TYPE.equals(type)) { request.setActionCode(ContactsRequest.ACTION_PICK_OR_CREATE_CONTACT); } else if (Phone.CONTENT_ITEM_TYPE.equals(type)) { request.setActionCode(ContactsRequest.ACTION_PICK_PHONE); } else if (Phones.CONTENT_ITEM_TYPE.equals(type)) { request.setActionCode(ContactsRequest.ACTION_PICK_PHONE); request.setLegacyCompatibilityMode(true); } else if (StructuredPostal.CONTENT_ITEM_TYPE.equals(type)) { request.setActionCode(ContactsRequest.ACTION_PICK_POSTAL); } else if (ContactMethods.CONTENT_POSTAL_ITEM_TYPE.equals(type)) { request.setActionCode(ContactsRequest.ACTION_PICK_POSTAL); request.setLegacyCompatibilityMode(true); } else if (People.CONTENT_ITEM_TYPE.equals(type)) { request.setActionCode(ContactsRequest.ACTION_PICK_OR_CREATE_CONTACT); request.setLegacyCompatibilityMode(true); } } else if (Intent.ACTION_INSERT_OR_EDIT.equals(action)) { request.setActionCode(ContactsRequest.ACTION_INSERT_OR_EDIT_CONTACT); } else if (Intent.ACTION_SEARCH.equals(action)) { // See if the suggestion was clicked with a search action key (call button) if ("call".equals(intent.getStringExtra(SearchManager.ACTION_MSG))) { String query = intent.getStringExtra(SearchManager.QUERY); if (!TextUtils.isEmpty(query)) { Intent newIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED, Uri.fromParts("tel", query, null)); request.setRedirectIntent(newIntent); } } else { request.setQueryString(intent.getStringExtra(SearchManager.QUERY)); request.setSearchMode(true); } } else if (Intent.ACTION_VIEW.equals(action)) { final String resolvedType = intent.resolveType(mContext); if (ContactsContract.Contacts.CONTENT_TYPE.equals(resolvedType) || android.provider.Contacts.People.CONTENT_TYPE.equals(resolvedType)) { request.setActionCode(ContactsRequest.ACTION_ALL_CONTACTS); } else { request.setActionCode(ContactsRequest.ACTION_VIEW_CONTACT); request.setContactUri(intent.getData()); intent.setAction(Intent.ACTION_DEFAULT); intent.setData(null); } } else if (UI.FILTER_CONTACTS_ACTION.equals(action)) { // When we get a FILTER_CONTACTS_ACTION, it represents search in the context // of some other action. Let's retrieve the original action to provide proper // context for the search queries. request.setActionCode(ContactsRequest.ACTION_DEFAULT); Bundle extras = intent.getExtras(); if (extras != null) { request.setQueryString(extras.getString(UI.FILTER_TEXT_EXTRA_KEY)); ContactsRequest originalRequest = (ContactsRequest) extras.get(ContactsSearchManager.ORIGINAL_REQUEST_KEY); if (originalRequest != null) { request.copyFrom(originalRequest); } } request.setSearchMode(true); // Since this is the filter activity it receives all intents // dispatched from the SearchManager for security reasons // so we need to re-dispatch from here to the intended target. } else if (Intents.SEARCH_SUGGESTION_CLICKED.equals(action)) { Uri data = intent.getData(); // See if the suggestion was clicked with a search action key (call button) if ("call".equals(intent.getStringExtra(SearchManager.ACTION_MSG))) { Intent newIntent = new Intent(mContext, CallContactActivity.class); newIntent.setData(data); request.setRedirectIntent(newIntent); } else { request.setActionCode(ContactsRequest.ACTION_VIEW_CONTACT); request.setContactUri(data); intent.setAction(Intent.ACTION_DEFAULT); intent.setData(null); } } else if (Intents.SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED.equals(action)) { request.setRedirectIntent(new Intent(Intent.ACTION_CALL_PRIVILEGED, intent.getData())); } else if (Intents.SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED.equals(action)) { // TODO actually support this in EditContactActivity. String number = intent.getData().getSchemeSpecificPart(); Intent newIntent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI); newIntent.putExtra(Intents.Insert.PHONE, number); request.setRedirectIntent(newIntent); } // Allow the title to be set to a custom String using an extra on the intent String title = intent.getStringExtra(UI.TITLE_EXTRA_KEY); if (title != null) { request.setActivityTitle(title); } return request; }