Example usage for android.content IntentFilter getDataPath

List of usage examples for android.content IntentFilter getDataPath

Introduction

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

Prototype

public final PatternMatcher getDataPath(int index) 

Source Link

Document

Return a data path in the filter.

Usage

From source file:com.github.michalbednarski.intentslab.browser.ComponentInfoFragment.java

static CharSequence dumpIntentFilter(IntentFilter filter, Resources res, boolean isBroadcast) {
    FormattedTextBuilder ftb = new FormattedTextBuilder();
    int tagColor = res.getColor(R.color.xml_tag);
    int attributeNameColor = res.getColor(R.color.xml_attr_name);
    int attributeValueColor = res.getColor(R.color.xml_attr_value);
    int commentColor = res.getColor(R.color.xml_comment);
    final String protectedComment = " <!-- " + res.getString(R.string.broadcast_action_protected_comment)
            + " -->";

    ftb.appendColoured("\n<intent-filter>", tagColor);

    for (int i = 0, j = filter.countActions(); i < j; i++) {
        final String action = filter.getAction(i);
        ftb.appendColoured("\n  <action", tagColor);
        ftb.appendColoured(" a:name=", attributeNameColor);
        ftb.appendColoured("\"" + action + "\"", attributeValueColor);
        ftb.appendColoured(">", tagColor);

        if (isBroadcast && Utils.isProtectedBroadcast(action)) {
            ftb.appendColoured(protectedComment, commentColor);
        }/*from   w w  w .j  av  a 2s .  com*/
    }

    for (int i = 0, j = filter.countCategories(); i < j; i++) {
        ftb.appendColoured("\n  <category", tagColor);
        ftb.appendColoured(" a:name=", attributeNameColor);
        ftb.appendColoured("\"" + filter.getCategory(i) + "\"", attributeValueColor);
        ftb.appendColoured(">", tagColor);
    }

    for (int i = 0, j = filter.countDataSchemes(); i < j; i++) {
        ftb.appendColoured("\n  <data", tagColor);
        ftb.appendColoured(" a:scheme=", attributeNameColor);
        ftb.appendColoured("\"" + filter.getDataScheme(i) + "\"", attributeValueColor);
        ftb.appendColoured(">", tagColor);
    }

    for (int i = 0, j = filter.countDataAuthorities(); i < j; i++) {
        IntentFilter.AuthorityEntry authority = filter.getDataAuthority(i);
        ftb.appendColoured("\n  <data", tagColor);
        ftb.appendColoured(" a:host=", attributeNameColor);
        ftb.appendColoured("\"" + authority.getHost() + "\"", attributeValueColor);
        if (authority.getPort() != -1) {
            ftb.appendColoured(" a:port=", attributeNameColor);
            ftb.appendColoured("\"" + authority.getPort() + "\"", attributeValueColor);
        }
        ftb.appendColoured(">", tagColor);
    }

    for (int i = 0, j = filter.countDataPaths(); i < j; i++) {
        PatternMatcher pathMatcher = filter.getDataPath(i);
        int type = pathMatcher.getType();
        ftb.appendColoured("\n  <data", tagColor);
        ftb.appendColoured(
                " a:path"
                        + (type == PatternMatcher.PATTERN_LITERAL ? ""
                                : type == PatternMatcher.PATTERN_PREFIX ? "Prefix"
                                        : type == PatternMatcher.PATTERN_SIMPLE_GLOB ? "Pattern" : "[unknown]")
                        + "=",
                attributeNameColor);
        ftb.appendColoured("\"" + pathMatcher.getPath() + "\"", attributeValueColor);
        ftb.appendColoured(">", tagColor);
    }

    for (int i = 0, j = filter.countDataTypes(); i < j; i++) {
        String dataType = filter.getDataType(i);
        if (!dataType.contains("/")) {
            // IntentFilter for partial types don't store "/*" at end
            // e.g. "image" instead of "image/*".
            // We display it in full form here
            dataType += "/*";
        }
        ftb.appendColoured("\n  <data", tagColor);
        ftb.appendColoured(" a:mimeType=", attributeNameColor);
        ftb.appendColoured("\"" + dataType + "\"", attributeValueColor);
        ftb.appendColoured(">", tagColor);
    }

    ftb.appendColoured("\n</intent-filter>", tagColor);
    return ftb.getText();
}

From source file:com.landenlabs.all_devtool.PackageFragment.java

/**
 * Get info on the preferred (launch by default) applications.
 * @return/* ww w. j  a  v  a 2s. co  m*/
 */
public String getPreferredAppInfo() {
    List<PackageInfo> packages = getActivity().getPackageManager().getInstalledPackages(0);
    List<IntentFilter> filters = new ArrayList<IntentFilter>();
    List<ComponentName> activities = new ArrayList<ComponentName>();
    String info = "";
    int nPref = 0, nFilters = 0, nActivities = 0;
    PackageInfo packInfo = null;
    // int orderCnt = 0;
    for (int i = 0; i < packages.size(); i++) {
        packInfo = packages.get(i);
        nPref = getActivity().getPackageManager().getPreferredActivities(filters, activities,
                packInfo.packageName);
        nFilters = filters.size();
        nActivities = activities.size();
        if (nPref > 0 || nFilters > 0 || nActivities > 0) {
            // This is a launch by default package
            // info += "\n" + packInfo.packageName + "\n";
            ArrayListPairString pkgList = new ArrayListPairString();

            for (IntentFilter filter : filters) {
                info += "IntentFilter:\n";
                for (int j = 0; j < filter.countActions(); j++) {
                    addList(pkgList, "Action", filter.getAction(j));
                }
                for (int j = 0; j < filter.countCategories(); j++) {
                    addList(pkgList, "Category", filter.getCategory(j));
                }
                for (int j = 0; j < filter.countDataTypes(); j++) {
                    addList(pkgList, "Type", filter.getDataType(j));
                }
                for (int j = 0; j < filter.countDataAuthorities(); j++) {
                    addList(pkgList, "Authority", filter.getDataAuthority(j).toString());
                }
                for (int j = 0; j < filter.countDataPaths(); j++) {
                    addList(pkgList, "Path", filter.getDataPath(j).toString());
                }
                for (int j = 0; j < filter.countDataSchemes(); j++) {
                    addList(pkgList, "Scheme", filter.getDataScheme(j));
                }
                // for (ComponentName activity : activities) {
                // info += "activity="
                // + activity.flattenToString() + "\n";
                // }
            }
            if (pkgList.size() != 0) {
                m_workList.add(new PackingItem(packInfo.packageName, pkgList, packInfo, i,
                        packInfo.applicationInfo.processName));
            }
        }
    }

    return info;
}