Example usage for android.os Bundle keySet

List of usage examples for android.os Bundle keySet

Introduction

In this page you can find the example usage for android.os Bundle keySet.

Prototype

public Set<String> keySet() 

Source Link

Document

Returns a Set containing the Strings used as keys in this Bundle.

Usage

From source file:Main.java

public static void dumpIntent(Intent i) {

    Bundle bundle = i.getExtras();
    if (bundle != null) {
        Set<String> keys = bundle.keySet();
        Iterator<String> it = keys.iterator();
        while (it.hasNext()) {
            String key = it.next();
        }//w  w  w . j ava  2s  .  c o  m
    }
}

From source file:Main.java

public static Map<String, String> bundleToMap(Bundle extras) {
    Map<String, String> map = new HashMap<String, String>();

    Set<String> ks = extras.keySet();
    Iterator<String> iterator = ks.iterator();
    while (iterator.hasNext()) {
        String key = iterator.next();
        map.put(key, extras.getString(key));
    }/*  w  w  w. j a va2 s .co m*/
    return map;
}

From source file:Main.java

/**
 * Convert an Android bundle to a hashtable
 * @param bundle/*  w ww.ja v a  2 s  .  c  o  m*/
 * @return
 */
public static Hashtable bundleToHashtable(Bundle bundle) {
    Hashtable retVal = new Hashtable();
    Set<String> keys = bundle.keySet();
    Iterator<String> iterator = keys.iterator();

    String key;
    Object val;
    while (iterator.hasNext()) {
        key = iterator.next();
        val = bundle.get(key);
        if (val instanceof String) {
            retVal.put(key, val);
        } else if (val instanceof Integer) {
            retVal.put(key, val);
        }
    }

    return retVal;
}

From source file:Main.java

public static void intentToAndroidLayoutMapper(Class<?> classObj, Intent intent, String prefixStr,
        Activity view) {/*  ww w .j a v  a 2 s  .c  om*/

    Bundle map = intent.getExtras();

    for (Object keyObj : map.keySet().toArray()) {
        String keyStr = keyObj.toString();
        Field fieldObj = null;
        try {
            fieldObj = classObj.getField(prefixStr + "_" + keyStr);
        } catch (NoSuchFieldException e) {
            continue;
        }
        Object layoutObj = null;
        try {
            layoutObj = fieldObj.get(fieldObj);
        } catch (IllegalAccessException e) {
            continue;
        }
        Integer layoutIntvalue = (Integer) layoutObj;

        View selectedView = view.findViewById(layoutIntvalue);

        if (selectedView instanceof TextView) {
            TextView textView = (TextView) selectedView;
            textView.setText((String) map.get(keyStr));
        } else if (selectedView instanceof ImageView) {
            ImageView imageView = (ImageView) selectedView;

        }

    }

}

From source file:Main.java

public static String encodeUrl(Bundle parameters, boolean sep) {
    String query = "";
    int x = 0;/*from   w ww .j a  v a 2s . com*/
    for (String key : parameters.keySet()) {

        String q = "?";
        if (sep == false)
            q = "&";
        query += (x == 0 ? q : "&") + key + "=" + parameters.getString(key);
        x++;

    }

    return query;

}

From source file:Main.java

public static String toString(Intent intent) {
    StringBuilder sb = new StringBuilder();
    sb.append(intent.getAction()).append(" ");

    Bundle bundle = intent.getExtras();
    if (bundle != null) {
        Set<String> sets = bundle.keySet();
        for (String key : sets) {
            if (bundle.get(key) instanceof Integer) {
                sb.append(key).append(":").append(bundle.getInt(key)).append("\n");
            } else if (bundle.get(key) instanceof ArrayList) {
                sb.append(key).append(":").append(Arrays.toString(bundle.getIntegerArrayList(key).toArray()))
                        .append("\n");
            } else if (bundle.get(key) instanceof Parcelable) {
                sb.append(key).append(":").append(bundle.getParcelable(key).toString()).append("\n");
            } else {
                sb.append(key).append(":").append(bundle.getString(key)).append("\n");
            }//from   w w w.  ja  v a2 s . c  o  m
        }

    }

    return sb.toString();
}

From source file:Main.java

/**
 * Remove all extras from intent/*  w ww .ja v  a2s.c o  m*/
 */
public static void clearExtras(Intent intent) {
    Bundle extras = intent.getExtras();
    if (extras == null) {
        return;
    }
    for (String key : extras.keySet()) {
        intent.removeExtra(key);
    }
}

From source file:Main.java

public static void addTaintInformationToIntent(Intent i, HashSet<String> taintCategories) {
    boolean intentHasNoExtras = i.getExtras() == null ? true : false;

    //A bit of limitation here, because we do only care about the extras
    if (!intentHasNoExtras) {
        Bundle extras = i.getExtras();

        String taintKeyName = generateKeyNameForTaintInfo(extras.keySet());

        String taintInformation = null;

        if (taintCategories.size() > 1)
            taintInformation = taintCategories.toString().substring(1, taintCategories.toString().length() - 1);
        else//from  ww  w.j  a  v a 2  s  . co  m
            taintInformation = taintCategories.iterator().next();

        i.putExtra(taintKeyName, taintInformation);
    }
}

From source file:Main.java

public static void addTaintInformationToIntent(Intent i, HashSet<String> taintCategories) {
    boolean intentHasNoExtras = i.getExtras() == null ? true : false;

    Log.i("PEP", "in addTaintInformationToIntent(Intent i, HashSet<String> taintCategories)");

    //A bit of limitation here, because we do only care about the extras
    if (!intentHasNoExtras) {
        Bundle extras = i.getExtras();

        String taintKeyName = generateKeyNameForTaintInfo(extras.keySet());

        String taintInformation = null;

        if (taintCategories.size() > 1)
            taintInformation = taintCategories.toString().substring(1, taintCategories.toString().length() - 1);
        else//from w  w  w.  java2s.  com
            taintInformation = taintCategories.iterator().next();

        i.putExtra(taintKeyName, taintInformation);
    }
}

From source file:Main.java

public static String deserialBundle(Bundle bundle) {
    if (bundle == null)
        return null;
    StringBuilder params = new StringBuilder();
    for (String key : bundle.keySet()) {
        params.append(key + "=" + bundle.get(key) + "&");
    }/* ww  w  . ja v a  2 s  . c om*/

    return params.length() > 0 ? params.substring(0, params.length() - 1) : null;
}