Example usage for android.content Intent resolveType

List of usage examples for android.content Intent resolveType

Introduction

In this page you can find the example usage for android.content Intent resolveType.

Prototype

public @Nullable String resolveType(@NonNull ContentResolver resolver) 

Source Link

Document

Return the MIME data type of this intent.

Usage

From source file:dev.drsoran.moloko.fragments.factories.AbstractIntentFragmentFactory.java

protected final static Fragment resolveIntentToFragment(Context context, Intent intent,
        List<Class<? extends Fragment>> fragmentClasses) {
    Fragment fragment = null;/*from ww w . j av  a 2  s.  c om*/

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

From source file:com.google.android.demos.atom.app.FeedActivity.java

private Uri getContentUri() {
    Intent intent = getIntent();
    Uri data = intent.getData();//from   w ww .  ja v  a 2  s.  c o m
    String type = intent.resolveType(this);
    if (Entries.CONTENT_TYPE.equals(type)) {
        return data;
    } else if ("application/atom+xml".equalsIgnoreCase(type)) {
        return Entries.contentUri(data.toString());
    } else {
        String channelUrl = mPreferences.getString(PREFERENCE_FEED, DEFAULT_FEED);
        return Entries.contentUri(channelUrl);
    }
}

From source file:edu.mit.mobile.android.locast.ver2.casts.VideoPlayer.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.videoplayer);

    mVideoView = (VideoView) findViewById(R.id.video);
    mMediaController = new MediaController(this);

    mMediaController.setMediaPlayer(mVideoView);
    mMediaController.setAnchorView(mVideoView);
    mVideoView.setOnPreparedListener(this);
    mVideoView.setOnErrorListener(this);
    mVideoView.setOnCompletionListener(this);

    mVideoView.setMediaController(mMediaController);

    mDescriptionView = (TextView) findViewById(R.id.description);
    mTitleView = (TextView) findViewById(R.id.title);

    final Intent intent = getIntent();

    final String action = intent.getAction();

    final String type = intent.resolveType(this);

    final LoaderManager lm = getSupportLoaderManager();

    setProgressBar(true);//from   w w  w. ja va 2  s  . c o  m

    if (MediaProvider.TYPE_CASTMEDIA_DIR.equals(type)) {
        lm.initLoader(LOADER_CASTMEDIA_DIR, null, this);

    } else if (MediaProvider.TYPE_CASTMEDIA_ITEM.equals(type)) {
        lm.initLoader(LOADER_CASTMEDIA_ITEM, null, this);
    }

    adjustForOrientation(getResources().getConfiguration());

}

From source file:edu.mit.mobile.android.locast.casts.VideoPlayer.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.videoplayer);

    mVideoView = (VideoView) findViewById(R.id.video);
    mMediaController = new MediaController(this);

    mMediaController.setMediaPlayer(mVideoView);
    mMediaController.setAnchorView(mVideoView);
    mVideoView.setOnPreparedListener(this);
    mVideoView.setOnErrorListener(this);
    mVideoView.setOnCompletionListener(this);

    mVideoView.setMediaController(mMediaController);

    mDescriptionView = (TextView) findViewById(R.id.description);
    mTitleView = (TextView) findViewById(R.id.title);

    final Intent intent = getIntent();

    final String action = intent.getAction();

    if (!Intent.ACTION_VIEW.equals(action)) {
        Toast.makeText(this, R.string.error_cast_could_not_play_video, Toast.LENGTH_LONG).show();
        Log.e(TAG, "received unhandled action to start activity: " + intent);
        setResult(RESULT_CANCELED);//from   w  w  w.  ja  va2s.c  o m
        finish();
        return;
    }

    final String type = intent.resolveType(this);

    final LoaderManager lm = getSupportLoaderManager();

    setProgressBar(true);

    if (MediaProvider.TYPE_CASTMEDIA_DIR.equals(type)) {
        lm.initLoader(LOADER_CASTMEDIA_DIR, null, this);

    } else if (MediaProvider.TYPE_CASTMEDIA_ITEM.equals(type)) {
        lm.initLoader(LOADER_CASTMEDIA_ITEM, null, this);
    }

    setFullscreen(true);
    adjustForOrientation(getResources().getConfiguration());

}

From source file:edu.mit.mobile.android.locast.ver2.casts.LocatableListWithMap.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map_list_activity);

    findViewById(R.id.refresh).setOnClickListener(this);
    findViewById(R.id.home).setOnClickListener(this);

    mMapView = (MapView) findViewById(R.id.map);
    mMapController = mMapView.getController();
    mListView = (ListView) findViewById(android.R.id.list);
    mListView.setOnItemClickListener(this);
    mListView.addFooterView(getLayoutInflater().inflate(R.layout.list_footer, null), null, false);
    mListView.setEmptyView(findViewById(android.R.id.empty));
    mRefresh = (RefreshButton) findViewById(R.id.refresh);
    mRefresh.setOnClickListener(this);
    mLoaderManager = getSupportLoaderManager();

    final Intent intent = getIntent();
    final String action = intent.getAction();

    mImageCache = ImageCache.getInstance(this);

    actionSearchNearby = ACTION_SEARCH_NEARBY.equals(action);
    final boolean actionView = Intent.ACTION_VIEW.equals(action);

    if (!actionView && !actionSearchNearby) {
        Log.e(TAG, "unhandled action " + action);
        finish();/*from  ww w  . j a v  a  2s .co m*/
        return;
    }

    CharSequence title;

    final Uri data = intent.getData();
    final String type = intent.resolveType(this);

    if (MediaProvider.TYPE_CAST_DIR.equals(type)) {
        mAdapter = new CastCursorAdapter(this, null);

        mListView.setAdapter(new ImageLoaderAdapter(this, mAdapter, mImageCache,
                new int[] { R.id.media_thumbnail }, 48, 48, ImageLoaderAdapter.UNIT_DIP));
        initMapOverlays(new CastsOverlay(this));

        title = getString(R.string.title_casts);

        searchRadius = 1500;

    } else if (MediaProvider.TYPE_EVENT_DIR.equals(type)) {

        title = getString(R.string.title_upcoming_events);
        searchRadius = 10000;

        mAdapter = new EventCursorAdapter(this, R.layout.browse_content_item, null,
                new String[] { Event._TITLE, Event._START_DATE },
                new int[] { android.R.id.text1, android.R.id.text2 }, new int[] {}, 0);

        mListView.setAdapter(mAdapter);
        initMapOverlays(new BasicLocatableOverlay(
                LocatableItemOverlay.boundCenterBottom(getResources().getDrawable(R.drawable.ic_map_event))));
    } else {
        throw new IllegalArgumentException("Unhandled content type " + type);
    }

    mBaseContent = data;
    setDataUri(data);

    if (actionSearchNearby) {
        title = getString(R.string.title_nearby, title);
    }
    // if it's showing only favorited items, adjust the title's language accordingly.
    final Boolean favorited = Favoritable.decodeFavoritedUri(data);
    if (favorited != null) {
        title = getString(favorited ? R.string.title_favorited : R.string.title_unfavorited, title);
    }

    setTitle(title);
    updateLocation();
    setRefreshing(true);
}

From source file:com.android.contacts.activities.DialtactsActivity.java

/**
 * Sets the current tab based on the intent's request type
 *
 * @param intent Intent that contains information about which tab should be selected
 *//*from  w  w  w  . j a  va  2s.  c o m*/
private void setCurrentTab(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;
    }

    // Remember the old manually selected tab index so that it can be restored if it is
    // overwritten by one of the programmatic tab selections
    final int savedTabIndex = mLastManuallySelectedFragment;

    final int tabIndex;
    if (DialpadFragment.phoneIsInUse() || isDialIntent(intent)) {
        tabIndex = TAB_INDEX_DIALER;
    } else if (recentCallsRequest) {
        tabIndex = TAB_INDEX_CALL_LOG;
    } else {
        tabIndex = mLastManuallySelectedFragment;
    }

    final int previousItemIndex = mViewPager.getCurrentItem();
    mViewPager.setCurrentItem(tabIndex, false /* smoothScroll */);
    if (previousItemIndex != tabIndex) {
        sendFragmentVisibilityChange(previousItemIndex, false /* not visible */ );
    }
    mPageChangeListener.setCurrentPosition(tabIndex);
    sendFragmentVisibilityChange(tabIndex, true /* visible */ );

    // Restore to the previous manual selection
    mLastManuallySelectedFragment = savedTabIndex;
    mDuringSwipe = false;
    mUserTabClick = false;
}

From source file:com.tasomaniac.openwith.resolver.ResolverActivity.java

protected void onIntentSelected(ResolveInfo ri, Intent intent, boolean alwaysCheck) {

    final ChooserHistory history = getHistory();

    if ((mAlwaysUseOption || mAdapter.hasFilteredItem()) && mAdapter.mOrigResolveList != null) {
        // Build a reasonable intent filter, based on what matched.
        IntentFilter filter = new IntentFilter();

        if (intent.getAction() != null) {
            filter.addAction(intent.getAction());
        }//from   ww w  .j  av a2 s .c  om
        Set<String> categories = intent.getCategories();
        if (categories != null) {
            for (String cat : categories) {
                filter.addCategory(cat);
            }
        }
        filter.addCategory(Intent.CATEGORY_DEFAULT);

        int cat = ri.match & IntentFilter.MATCH_CATEGORY_MASK;
        Uri data = intent.getData();
        if (cat == IntentFilter.MATCH_CATEGORY_TYPE) {
            String mimeType = intent.resolveType(this);
            if (mimeType != null) {
                try {
                    filter.addDataType(mimeType);
                } catch (IntentFilter.MalformedMimeTypeException e) {
                    Log.w("ResolverActivity", e);
                    filter = null;
                }
            }
        }
        if (filter != null && data != null && data.getScheme() != null) {
            // We need the data specification if there was no type,
            // OR if the scheme is not one of our magical "file:"
            // or "content:" schemes (see IntentFilter for the reason).
            if (cat != IntentFilter.MATCH_CATEGORY_TYPE
                    || (!"file".equals(data.getScheme()) && !"content".equals(data.getScheme()))) {
                filter.addDataScheme(data.getScheme());

                // Look through the resolved filter to determine which part
                // of it matched the original Intent.
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
                    Iterator<PatternMatcher> pIt = ri.filter.schemeSpecificPartsIterator();

                    if (pIt != null) {
                        String ssp = data.getSchemeSpecificPart();
                        while (ssp != null && pIt.hasNext()) {
                            PatternMatcher p = pIt.next();
                            if (p.match(ssp)) {
                                filter.addDataSchemeSpecificPart(p.getPath(), p.getType());
                                break;
                            }
                        }
                    }
                }
                Iterator<IntentFilter.AuthorityEntry> aIt = ri.filter.authoritiesIterator();
                if (aIt != null) {
                    while (aIt.hasNext()) {
                        IntentFilter.AuthorityEntry a = aIt.next();
                        if (a.match(data) >= 0) {
                            int port = a.getPort();
                            filter.addDataAuthority(a.getHost(), port >= 0 ? Integer.toString(port) : null);
                            break;
                        }
                    }
                }
                Iterator<PatternMatcher> pIt = ri.filter.pathsIterator();
                if (pIt != null) {
                    String path = data.getPath();
                    while (path != null && pIt.hasNext()) {
                        PatternMatcher p = pIt.next();
                        if (p.match(path)) {
                            filter.addDataPath(p.getPath(), p.getType());
                            break;
                        }
                    }
                }
            }
        }

        if (filter != null) {
            ContentValues values = new ContentValues(3);
            values.put(HOST, mRequestedUri.getHost());
            values.put(COMPONENT, intent.getComponent().flattenToString());

            if (alwaysCheck) {
                values.put(PREFERRED, true);
            }
            values.put(LAST_CHOSEN, true);
            getContentResolver().insert(CONTENT_URI, values);

            history.add(intent.getComponent().getPackageName());
        }
    }

    if (intent != null) {
        startActivity(intent);
    }
    history.save(this);
}

From source file:edu.mit.mobile.android.locast.casts.LocatableListWithMap.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map_list_activity);
    mProgressBar = (NotificationProgressBar) (findViewById(R.id.progressNotification));
    findViewById(R.id.refresh).setOnClickListener(this);
    findViewById(R.id.home).setOnClickListener(this);

    mMapView = (MyMapView) findViewById(R.id.map);
    mMapController = mMapView.getController();
    mListView = (ListView) findViewById(android.R.id.list);
    mListView.setOnItemClickListener(this);
    mListView.addFooterView(getLayoutInflater().inflate(R.layout.list_footer, null), null, false);
    mListView.setEmptyView(findViewById(R.id.progressNotification));
    mRefresh = (RefreshButton) findViewById(R.id.refresh);
    mRefresh.setOnClickListener(this);
    mLoaderManager = getSupportLoaderManager();

    final Intent intent = getIntent();
    final String action = intent.getAction();

    mImageCache = ImageCache.getInstance(this);

    actionSearchNearby = ACTION_SEARCH_NEARBY.equals(action);
    final boolean actionView = Intent.ACTION_VIEW.equals(action);

    if (!actionView && !actionSearchNearby) {
        Log.e(TAG, "unhandled action " + action);
        finish();/*from w  ww  .j a  v  a 2  s  .  c  o  m*/
        return;
    }

    mMapView.setOnChangeListener(new MyMapView.OnChangeListener() {

        @Override
        public void onChange(MapView view, GeoPoint newCenter, GeoPoint oldCenter, int newZoom, int oldZoom) {
            Log.d(TAG, "onChange triggered");
            if (!oldCenter.equals(newCenter)) {
                mUserPanned = true;
                Log.d(TAG, "centers are different, requesting a reload");
                mHandler.obtainMessage(MSG_SET_GEOPOINT, mSearchRadius, 0, newCenter).sendToTarget();
            }
        }
    });

    CharSequence title;

    final Uri data = intent.getData();
    final String type = intent.resolveType(this);

    if (MediaProvider.TYPE_CAST_DIR.equals(type)) {
        mAdapter = new CastCursorAdapter(this, null);

        mListView.setAdapter(new ImageLoaderAdapter(this, mAdapter, mImageCache,
                new int[] { R.id.media_thumbnail }, 48, 48, ImageLoaderAdapter.UNIT_DIP));
        initMapOverlays(new CastsOverlay(this, mMapView));

        title = getString(R.string.title_casts);

        mSearchRadius = 1500;

    } else {
        throw new IllegalArgumentException("Unhandled content type " + type);
    }

    mBaseContent = data;
    setDataUri(data);

    if (actionSearchNearby) {
        title = getString(R.string.title_nearby, title);
    }
    // if it's showing only favorited items, adjust the title's language accordingly.
    final Boolean favorited = Favoritable.decodeFavoritedUri(data);
    if (favorited != null) {
        title = getString(favorited ? R.string.title_favorited : R.string.title_unfavorited, title);
    }

    try {
        final Set<String> tags = TaggableItem.getTagsFromUri(data);

        title = getString(R.string.cast_list_tags, TextUtils.join(", ", tags));
    } catch (final IllegalArgumentException e) {
        // that's fine, we didn't need to set it!
    }

    setTitle(title);
    if (actionSearchNearby) {
        updateLocation();
    }
    setRefreshing(true);
}

From source file:org.openintents.shopping.ui.ShoppingActivity.java

/**
 * Called when the activity is first created.
 *///w  ww .j  a va 2  s.c  o m
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    if (debug) {
        Log.d(TAG, "Shopping list onCreate()");
    }

    mSortOrder = PreferenceActivity.getShoppingListSortOrderFromPrefs(this);

    mDistribution.setFirst(MENU_DISTRIBUTION_START, DIALOG_DISTRIBUTION_START);

    // Check whether EULA has been accepted
    // or information about new version can be presented.
    if (false && mDistribution.showEulaOrNewVersion()) {
        return;
    }

    setContentView(R.layout.activity_shopping);

    // mEditItemPosition = -1;

    // Automatic requeries (once a second)
    mUpdateInterval = 2000;
    mUpdating = false;

    // General Uris:
    mListUri = ShoppingContract.Lists.CONTENT_URI;
    mItemUri = ShoppingContract.Items.CONTENT_URI;
    mListItemUri = ShoppingContract.Items.CONTENT_URI;

    int defaultShoppingList = getLastUsedListFromPrefs();

    // Handle the calling intent
    final Intent intent = getIntent();
    final String type = intent.resolveType(this);
    final String action = intent.getAction();

    if (action == null) {
        // Main action
        mState = STATE_MAIN;

        mListUri = Uri.withAppendedPath(ShoppingContract.Lists.CONTENT_URI, "" + defaultShoppingList);

        intent.setData(mListUri);
    } else if (Intent.ACTION_MAIN.equals(action)) {
        // Main action
        mState = STATE_MAIN;

        mListUri = Uri.withAppendedPath(ShoppingContract.Lists.CONTENT_URI, "" + defaultShoppingList);

        intent.setData(mListUri);

    } else if (Intent.ACTION_VIEW.equals(action)) {
        mState = STATE_VIEW_LIST;

        setListUriFromIntent(intent.getData(), type);
    } else if (Intent.ACTION_INSERT.equals(action)) {

        mState = STATE_VIEW_LIST;

        setListUriFromIntent(intent.getData(), type);

    } else if (Intent.ACTION_PICK.equals(action)) {
        mState = STATE_PICK_ITEM;

        mListUri = Uri.withAppendedPath(ShoppingContract.Lists.CONTENT_URI, "" + defaultShoppingList);
    } else if (Intent.ACTION_GET_CONTENT.equals(action)) {
        mState = STATE_GET_CONTENT_ITEM;

        mListUri = Uri.withAppendedPath(ShoppingContract.Lists.CONTENT_URI, "" + defaultShoppingList);
    } else if (GeneralIntents.ACTION_INSERT_FROM_EXTRAS.equals(action)) {
        if (ShoppingListIntents.TYPE_STRING_ARRAYLIST_SHOPPING.equals(type)) {
            /*
             * Need to insert new items from a string array in the intent
            * extras Use main action but add an item to the options menu
            * for adding extra items
            */
            getShoppingExtras(intent);
            mState = STATE_MAIN;
            mListUri = Uri.withAppendedPath(ShoppingContract.Lists.CONTENT_URI, "" + defaultShoppingList);
            intent.setData(mListUri);
        } else if (intent.getDataString().startsWith(ShoppingContract.Lists.CONTENT_URI.toString())) {
            // Somewhat quick fix to pass data from ShoppingListsActivity to
            // this activity.

            // We received a valid shopping list URI:
            mListUri = intent.getData();

            getShoppingExtras(intent);
            mState = STATE_MAIN;
            intent.setData(mListUri);
        }
    } else {
        // Unknown action.
        Log.e(TAG, "Shopping: Unknown action, exiting");
        finish();
        return;
    }

    // hook up all buttons, lists, edit text:
    createView();

    // populate the lists
    fillListFilter();

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    // Get last part of URI:
    int selectList;
    try {
        selectList = Integer.parseInt(mListUri.getLastPathSegment());
    } catch (NumberFormatException e) {
        selectList = defaultShoppingList;
    }

    // select the default shopping list at the beginning:
    setSelectedListId(selectList);

    if (icicle != null) {
        String prevText = icicle.getString(ORIGINAL_ITEM);
        if (prevText != null) {
            mEditText.setTextKeepState(prevText);
        }
        // mTextEntryMenu = icicle.getInt(BUNDLE_TEXT_ENTRY_MENU);
        // mEditItemPosition = icicle.getInt(BUNDLE_CURSOR_ITEMS_POSITION);
        mItemUri = Uri.parse(icicle.getString(BUNDLE_ITEM_URI));
        List<String> pathSegs = mItemUri.getPathSegments();
        int num = pathSegs.size();
        mListItemUri = Uri.withAppendedPath(mListUri, pathSegs.get(num - 1));
        if (icicle.containsKey(BUNDLE_RELATION_URI)) {
            mRelationUri = Uri.parse(icicle.getString(BUNDLE_RELATION_URI));
        }
        mItemsView.mMode = icicle.getInt(BUNDLE_MODE);
        mItemsView.mModeBeforeSearch = icicle.getInt(BUNDLE_MODE_BEFORE_SEARCH);
    }

    // set focus to the edit line:
    mEditText.requestFocus();

    // TODO remove initFromPreferences from onCreate
    // we need it in resume to update after settings have changed
    initFromPreferences();
    // now update title and fill all items
    onModeChanged();

    mItemsView.setActionBarListener(this);
    mItemsView.setUndoListener(this);

    if ("myo".equals(BuildConfig.FLAVOR)) {
        try {
            Class myoToggleBoughtInputMethod = Class
                    .forName("org.openintents.shopping.ui.MyoToggleBoughtInputMethod");
            Constructor constructor = myoToggleBoughtInputMethod
                    .getConstructor(new Class[] { ShoppingActivity.class, mItemsView.getClass() });
            toggleBoughtInputMethod = (ToggleBoughtInputMethod) constructor
                    .newInstance(new Object[] { this, mItemsView });
        } catch (ClassNotFoundException e) {
        } catch (NoSuchMethodException e) {
        } catch (InvocationTargetException e) {
        } catch (InstantiationException e) {
        } catch (IllegalAccessException e) {
        }
    }
}