protected static final Fragment resolveIntentToFragment( Context context, Intent intent, List<Class<? extends Fragment>> fragmentClasses) { Fragment fragment = null; try { for (Iterator<Class<? extends Fragment>> i = fragmentClasses.iterator(); i.hasNext() && fragment == null; ) { final Class<? extends Fragment> entry = i.next(); final IntentFilter filter = (IntentFilter) entry.getMethod("getIntentFilter").invoke(null); if (filter.matchAction(intent.getAction()) && filter.matchData(intent.resolveType(context), intent.getScheme(), intent.getData()) > 0) { fragment = DefaultFragmentFactory.create(context, entry, intent.getExtras()); } } } catch (Throwable e) { MolokoApp.Log.e( AbstractIntentFragmentFactory.class, "Unable to instantiate new fragment by Intent " + intent, e); } return fragment; }
/** * @hide Ask that a new activity be started for voice interaction. This will create a new * dedicated task in the activity manager for this voice interaction session; this means that * {@link Intent#FLAG_ACTIVITY_NEW_TASK Intent.FLAG_ACTIVITY_NEW_TASK} will be set for you to * make it a new task. * <p>The newly started activity will be displayed to the user in a special way, as a layer * under the voice interaction UI. * <p>As the voice activity runs, it can retrieve a {@link android.app.VoiceInteractor} * through which it can perform voice interactions through your session. These requests for * voice interactions will appear as callbacks on {@link #onGetSupportedCommands}, {@link * #onConfirm}, {@link #onCommand}, and {@link #onCancel}. * <p>You will receive a call to {@link #onTaskStarted} when the task starts up and {@link * #onTaskFinished} when the last activity has finished. * @param intent The Intent to start this voice interaction. The given Intent will always have * {@link Intent#CATEGORY_VOICE Intent.CATEGORY_VOICE} added to it, since this is part of a * voice interaction. */ @SystemApi public void startVoiceActivity(Intent intent) { if (mToken == null) { throw new IllegalStateException("Can't call before onCreate()"); } try { intent.migrateExtraStreamToClipData(); intent.prepareToLeaveProcess(); int res = mSystemService.startVoiceActivity( mToken, intent, intent.resolveType(mContext.getContentResolver())); Instrumentation.checkStartActivityResult(res, intent); } catch (RemoteException e) { } }
public static int determineTypeBits(Context context, Intent intent) { int typeBits = 0; String type = intent.resolveType(context); if (MIME_TYPE_ALL.equals(type)) { typeBits = DataManager.INCLUDE_ALL; } else if (MIME_TYPE_IMAGE.equals(type) || DIR_TYPE_IMAGE.equals(type)) { typeBits = DataManager.INCLUDE_IMAGE; } else if (MIME_TYPE_VIDEO.equals(type) || DIR_TYPE_VIDEO.equals(type)) { typeBits = DataManager.INCLUDE_VIDEO; } else { typeBits = DataManager.INCLUDE_ALL; } if (intent.getBooleanExtra(Intent.EXTRA_LOCAL_ONLY, false)) { typeBits |= DataManager.INCLUDE_LOCAL_ONLY; } return typeBits; }
/** * Sets the current tab based on the intent's request type * * @param intent Intent that contains information about which tab should be selected */ private void displayFragment(Intent intent) { // If we got here by hitting send and we're in call forward along to the in-call activity boolean recentCallsRequest = Calls.CONTENT_TYPE.equals(intent.resolveType(getContentResolver())); if (isSendKeyWhileInCall(intent, recentCallsRequest)) { finish(); return; } if (mDialpadFragment != null) { final boolean phoneIsInUse = phoneIsInUse(); if (phoneIsInUse || isDialIntent(intent)) { mDialpadFragment.setStartedFromNewIntent(true); if (phoneIsInUse && !mDialpadFragment.isVisible()) { mInCallDialpadUp = true; } showDialpadFragment(false); } } }
@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; }