Example usage for android.content IntentFilter matchData

List of usage examples for android.content IntentFilter matchData

Introduction

In this page you can find the example usage for android.content IntentFilter matchData.

Prototype

public final int matchData(String type, String scheme, Uri data) 

Source Link

Document

Match this filter against an Intent's data (type, scheme and path).

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  w w w. j  ava  2 s .c o  m

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