Java Code Examples for android.content.IntentFilter#match()

The following examples show how to use android.content.IntentFilter#match() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntentMatchFilterTest.java    From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testMimeType1()
{
	try
	{
		Intent i = getIntent();
		i.setType("iccta");
		
		IntentFilter f = getIntentFilter();
		f.addDataType("iccta/*");
		
		int v = f.match(i.getAction(), i.getType(), i.getScheme(), i.getData(), i.getCategories(), "IccTA");
		
		Assert.assertTrue(v > 0);
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
		Assert.fail();
	}
}
 
Example 2
Source File: IntentMatchFilterTest.java    From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testMimeType2()
{
	try
	{
		Intent i = getIntent();
		i.setType("iccta/123");
		
		IntentFilter f = getIntentFilter();
		f.addDataType("iccta/*");
		
		int v = f.match(i.getAction(), i.getType(), i.getScheme(), i.getData(), i.getCategories(), "IccTA");
		
		Assert.assertTrue(v > 0);
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
		Assert.fail();
	}
}
 
Example 3
Source File: IntentMatchFilterTest.java    From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testMimeType3()
{
	try
	{
		Intent i = getIntent();
		i.setType("iccta/*");
		
		IntentFilter f = getIntentFilter();
		f.addDataType("iccta/123");
		
		int v = f.match(i.getAction(), i.getType(), i.getScheme(), i.getData(), i.getCategories(), "IccTA");
		
		Assert.assertTrue(v > 0);
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
		Assert.fail();
	}
}
 
Example 4
Source File: IntentMatchFilterTest.java    From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testMimeType4()
{
	try
	{
		Intent i = getIntent();
		i.setType("iccta/123");
		
		IntentFilter f = getIntentFilter();
		f.addDataType("iccta/123");
		
		int v = f.match(i.getAction(), i.getType(), i.getScheme(), i.getData(), i.getCategories(), "IccTA");
		
		Assert.assertTrue(v > 0);
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
		Assert.fail();
	}
}
 
Example 5
Source File: IntentMatchFilterTest.java    From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testMimeType5()
{
	try
	{
		Intent i = getIntent();
		i.setType("123/*");
		
		IntentFilter f = getIntentFilter();
		f.addDataType("123/iccta");
		
		int v = f.match(i.getAction(), i.getType(), i.getScheme(), i.getData(), i.getCategories(), "IccTA");
		
		Assert.assertTrue(v > 0);
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
		Assert.fail();
	}
}
 
Example 6
Source File: IntentMatchFilterTest.java    From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testMimeType6()
{
	try
	{
		Intent i = getIntent();
		i.setType("*/123");
		
		IntentFilter f = getIntentFilter();
		f.addDataType("1234/123");
		
		int v = f.match(i.getAction(), i.getType(), i.getScheme(), i.getData(), i.getCategories(), "IccTA");
		
		Assert.assertTrue(v < 0);
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
		Assert.fail();
	}
}
 
Example 7
Source File: IntentMatchFilterTest.java    From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testMimeType7()
{
	try
	{
		Intent i = getIntent();
		i.setType("*");
		
		IntentFilter f = getIntentFilter();
		f.addDataType("abc/123");
		
		int v = f.match(i.getAction(), i.getType(), i.getScheme(), i.getData(), i.getCategories(), "IccTA");
		
		Assert.assertTrue(v < 0);
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
		Assert.fail();
	}
}
 
Example 8
Source File: PluginPackageInfo.java    From Neptune with Apache License 2.0 5 votes vote down vote up
/**
 * 查找能够响应这个Intent的Activity
 */
public ActivityInfo resolveActivity(Intent intent) {
    if (intent == null) {
        return null;
    }
    if (mActivityIntentInfos != null) {
        ComponentName compName = intent.getComponent();
        String className = null;
        if (compName != null) {
            className = compName.getClassName();
        }
        if (!TextUtils.isEmpty(className)) {
            ActivityIntentInfo act = mActivityIntentInfos.get(className);
            if (act != null) {
                return act.mInfo;
            }
        } else {
            for (ActivityIntentInfo info : mActivityIntentInfos.values()) {
                if (info != null && info.mFilter != null) {
                    for (IntentFilter filter : info.mFilter) {
                        if (filter.match(intent.getAction(), intent.getType(), intent.getScheme(), intent.getData(),
                                intent.getCategories(), TAG) > 0) {
                            return info.mInfo;
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
Example 9
Source File: PluginPackageInfo.java    From Neptune with Apache License 2.0 5 votes vote down vote up
/**
 * 查找能够响应这个Intent的Service
 */
public ServiceInfo resolveService(Intent intent) {
    if (intent == null) {
        return null;
    }

    if (mServiceIntentInfos != null) {
        ComponentName compName = intent.getComponent();
        String className = null;
        if (compName != null) {
            className = compName.getClassName();
        }
        if (!TextUtils.isEmpty(className)) {
            ServiceIntentInfo service = mServiceIntentInfos.get(className);
            if (service != null) {
                return service.mInfo;
            }
        } else {
            for (ServiceIntentInfo info : mServiceIntentInfos.values()) {
                if (info != null && info.mFilter != null) {
                    for (IntentFilter filter : info.mFilter) {
                        if (filter.match(intent.getAction(), null, intent.getScheme(), intent.getData(),
                                intent.getCategories(), TAG) > 0) {
                            return info.mInfo;
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
Example 10
Source File: PluginPackageInfo.java    From Neptune with Apache License 2.0 5 votes vote down vote up
/**
 * 查找能够响应这个Intent的Recevier
 */
public ActivityInfo resolveReceiver(Intent mIntent) {
    if (mIntent == null) {
        return null;
    }
    if (mReceiverIntentInfos != null) {
        ComponentName compName = mIntent.getComponent();
        String className = null;
        if (compName != null) {
            className = compName.getClassName();
        }
        if (!TextUtils.isEmpty(className)) {
            ReceiverIntentInfo mReceiverInfo = mReceiverIntentInfos.get(className);
            if (mReceiverInfo != null) {
                return mReceiverInfo.mInfo;
            }
        } else {
            for (ReceiverIntentInfo info : mReceiverIntentInfos.values()) {
                if (info != null && info.mFilter != null) {
                    for (IntentFilter filter : info.mFilter) {
                        if (filter.match(mIntent.getAction(), null, null, null,
                                null, TAG) > 0) {
                            return info.mInfo;
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
Example 11
Source File: IntentMatcherHelper.java    From springreplugin with Apache License 2.0 4 votes vote down vote up
/**
 * 根据 Intent 匹配组件
 *
 * @param context    Context
 * @param intent     调用方传来的 Intent
 * @param filtersMap 插件中声明的所有组件和 IntentFilter
 * @return ComponentInfo
 */
public static String doMatchIntent(Context context, Intent intent, Map<String, List<IntentFilter>> filtersMap) {
    if (filtersMap == null) {
        return null;
    }

    final String action = intent.getAction();
    final String type = intent.resolveTypeIfNeeded(context.getContentResolver());
    final Uri data = intent.getData();
    final String scheme = intent.getScheme();
    final Set<String> categories = intent.getCategories();

    for (Map.Entry<String, List<IntentFilter>> entry : filtersMap.entrySet()) {
        String pluginName = entry.getKey();
        List<IntentFilter> filters = entry.getValue();
        if (filters == null) {
            continue;
        }

        for (IntentFilter filter : filters) {
            int match = filter.match(action, type, scheme, data, categories, "ComponentList");
            if (match >= 0) {
                if (LOG) {
                    LogDebug.d(TAG, "IntentFilter 匹配成功: " + entry.getKey());
                }
                return pluginName;
            } else {
                if (LOG) {
                    String reason;
                    switch (match) {
                        case IntentFilter.NO_MATCH_ACTION:
                            reason = "action";
                            break;
                        case IntentFilter.NO_MATCH_CATEGORY:
                            reason = "category";
                            break;
                        case IntentFilter.NO_MATCH_DATA:
                            reason = "data";
                            break;
                        case IntentFilter.NO_MATCH_TYPE:
                            reason = "type";
                            break;
                        default:
                            reason = "unknown reason";
                            break;
                    }
                    LogDebug.d(TAG, "  Filter did not match: " + reason);
                }
            }
        }
    }
    return "";
}