Android Intent Set initIntentFilterFromXml(IntentFilter inf, XmlPullParser xpp)

Here you can find the source of initIntentFilterFromXml(IntentFilter inf, XmlPullParser xpp)

Description

init Intent Filter From Xml

License

Open Source License

Declaration

private static final boolean initIntentFilterFromXml(IntentFilter inf,
            XmlPullParser xpp) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.xmlpull.v1.XmlPullParser;

import android.content.IntentFilter;
import android.content.IntentFilter.MalformedMimeTypeException;

import android.os.PatternMatcher;

public class Main {
    private static final boolean initIntentFilterFromXml(IntentFilter inf,
            XmlPullParser xpp) {//from ww w.j  av a 2s .  c  o m
        try {
            int outerDepth = xpp.getDepth();
            int type;
            final String NAME = "name";
            while ((type = xpp.next()) != XmlPullParser.END_DOCUMENT
                    && (type != XmlPullParser.END_TAG || xpp.getDepth() > outerDepth)) {
                if (type == XmlPullParser.END_TAG
                        || type == XmlPullParser.TEXT)
                    continue;
                String tag = xpp.getName();
                if (tag.equals("action")) {
                    String name = xpp.getAttributeValue(null, NAME);
                    if (name != null)
                        inf.addAction(name);
                } else if (tag.equals("category")) {
                    String name = xpp.getAttributeValue(null, NAME);
                    if (name != null)
                        inf.addCategory(name);
                } else if (tag.equals("data")) {
                    int na = xpp.getAttributeCount();
                    for (int i = 0; i < na; i++) {
                        String port = null;
                        String an = xpp.getAttributeName(i);
                        String av = xpp.getAttributeValue(i);
                        if ("mimeType".equals(an)) {
                            try {
                                inf.addDataType(av);
                            } catch (MalformedMimeTypeException e) {
                            }
                        } else if ("scheme".equals(an)) {
                            inf.addDataScheme(av);
                        } else if ("host".equals(an)) {
                            inf.addDataAuthority(av, port);
                        } else if ("port".equals(an)) {
                            port = av;
                        } else if ("path".equals(an)) {
                            inf.addDataPath(av,
                                    PatternMatcher.PATTERN_LITERAL);
                        } else if ("pathPrefix".equals(an)) {
                            inf.addDataPath(av,
                                    PatternMatcher.PATTERN_PREFIX);
                        } else if ("pathPattern".equals(an)) {
                            inf.addDataPath(av,
                                    PatternMatcher.PATTERN_SIMPLE_GLOB);
                        }
                    }
                }
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}

Related

  1. pushNotification(Context context, int notId, PendingIntent pIntent, int iconRID, String title, String summary, boolean autoCancel, boolean vibrate, boolean light, boolean sound)
  2. updateIntentExplicitness(Context context, Intent implicitIntent)
  3. getAppStartIntent(Context context)
  4. dumpBundleKeys(Intent intent)