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 String getStringByCaseInsensitive(Bundle bundle, String key) {
    Set<String> keys = bundle.keySet();
    String lower = key.toLowerCase();
    for (String k : keys) {
        if (k.toLowerCase().equals(lower))
            return bundle.getString(k);
    }//from  w w  w.  j a  v  a  2 s .  c o  m

    return null;
}

From source file:Main.java

public static void dumpIntent(Intent intent) {
    System.out.println("action: " + intent.getAction());
    System.out.println("data: " + intent.getData());
    System.out.println("extras:");
    Bundle bundle = intent.getExtras();
    for (String key : bundle.keySet()) {
        Object object = bundle.get(key);
        System.out.println(key + "->" + object + "(" + object.getClass().getName() + ")");
    }//ww  w. j av a  2 s .c o  m
}

From source file:Main.java

public static String bundle2string(Bundle bundle) {
    String string = "{";
    for (String key : bundle.keySet()) {
        string += " " + key + " => " + bundle.get(key) + ";";
    }/*from w ww .  j a va  2  s  .c o m*/
    string += " }";
    return string;
}

From source file:Main.java

public static String printBundle(Bundle bundle) {
    StringBuilder sb = new StringBuilder();
    for (String key : bundle.keySet()) {
        sb.append("\nkey:" + key + ", value:" + bundle.getString(key));
    }//from   w  w  w  .  java  2s .  c  o m
    return sb.toString();
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
public static PersistableBundle bundleToPersistableBundle(Bundle bundle) {
    Set<String> keySet = bundle.keySet();
    PersistableBundle persistableBundle = new PersistableBundle();
    for (String key : keySet) {
        Object value = bundle.get(key);
        if (value instanceof Boolean) {
            persistableBundle.putBoolean(key, (boolean) value);
        } else if (value instanceof Integer) {
            persistableBundle.putInt(key, (int) value);
        } else if (value instanceof String) {
            persistableBundle.putString(key, (String) value);
        } else if (value instanceof String[]) {
            persistableBundle.putStringArray(key, (String[]) value);
        } else if (value instanceof Bundle) {
            PersistableBundle innerBundle = bundleToPersistableBundle((Bundle) value);
            persistableBundle.putPersistableBundle(key, innerBundle);
        }/* ww w .ja  v a 2s.  co  m*/
    }
    return persistableBundle;
}

From source file:Main.java

public static void dumpBatteryStats(Context context) {
    IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    Intent batteryStatus = context.registerReceiver(null, ifilter);

    Bundle bundle = batteryStatus.getExtras();
    for (String key : bundle.keySet()) {
        Object value = bundle.get(key);
        Log.d(TAG, String.format("Battery,%s=%s (%s)", key, value.toString(), value.getClass().getName()));
    }/*from   ww  w .  j  a  v a 2s . c o  m*/
}

From source file:Main.java

public static void LogBundleExtras(Bundle bundle) {
    for (String key : bundle.keySet()) {
        Object value = bundle.get(key);

        StringBuilder builder = new StringBuilder();
        builder.append("key: ");
        builder.append(key);//from w  w w  .ja v a  2  s.  co  m
        builder.append("\t\t\t\t");

        if (value != null) {

            builder.append("key: ");
            builder.append(key);
            builder.append("\t\t\t\t");

            if (value instanceof CharSequence[]) {
                builder.append("\n====== Charsequense[]======\n");

                for (CharSequence seq : bundle.getCharSequenceArray(key)) {
                    builder.append("value(charseq): ");
                    builder.append(seq);
                    builder.append("\n");
                }
                builder.append("====== \"Charsequense[]======\n");
            } else {
                builder.append("value: ");
                builder.append(value);
                builder.append("\t");
            }

            builder.append("value class: ");
            builder.append(value.getClass().getName());
        } else

            builder.append("value: null");

        Log.d(TAG, builder.toString());
    }
}

From source file:Main.java

public static Map<String, String> fromBundle(Bundle input) {
    Map<String, String> output = new HashMap<String, String>();
    for (String key : input.keySet()) {
        output.put(key, input.getString(key));
    }//w ww . j  a  v  a 2 s  .co  m
    return output;
}

From source file:Main.java

public static String sprintBundle(Bundle bundle) {
    StringBuilder sb = new StringBuilder();
    for (String key : bundle.keySet()) {
        sb.append(key);/*w w  w  . jav a  2 s. c om*/
        sb.append(" => ");
        sb.append(bundle.get(key));
        sb.append("\n");
    }
    return sb.toString();
}

From source file:Main.java

public static <T extends Parcelable> Map<String, T> fromBundle(Bundle input, Class<T> c) {
    Map<String, T> output = new HashMap<String, T>();
    for (String key : input.keySet()) {
        output.put(key, c.cast(input.getParcelable(key)));
    }/*from  ww w .  ja v  a 2 s .  c  o  m*/
    return output;
}