Example usage for android.os Bundle get

List of usage examples for android.os Bundle get

Introduction

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

Prototype

@Nullable
public Object get(String key) 

Source Link

Document

Returns the entry with the given key as an object.

Usage

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) + "&");
    }//from ww w .  j ava 2 s . c  o m

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

From source file:Main.java

public static String sprintBundle(Bundle bundle) {
    StringBuilder sb = new StringBuilder();
    for (String key : bundle.keySet()) {
        sb.append(key);//from www . j  a  v  a2s  . c o m
        sb.append(" => ");
        sb.append(bundle.get(key));
        sb.append("\n");
    }
    return sb.toString();
}

From source file:Main.java

public static Map<String, String> bundleToMap(Bundle bundle) {
    if (bundle == null)
        return null;
    Map<String, String> map = new HashMap<String, String>();
    for (String key : bundle.keySet()) {
        map.put(key, bundle.get(key).toString());
    }/* w  ww  .ja  v  a2 s.  co m*/
    return map;
}

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 .  j  a va2 s. c o  m*/
        }

    }

    return sb.toString();
}

From source file:Main.java

public static <T> Map<String, T> fromBundle(Bundle input, Class<T> claz) {
    input.setClassLoader(claz.getClassLoader());
    Map<String, T> output = new ArrayMap<String, T>();
    for (String key : input.keySet()) {
        output.put(key, (T) input.get(key));
    }//w w  w .  java 2 s.c om
    return output;
}

From source file:Main.java

/**
 * Convert bundle to readable string/*  w  w  w. j  a v  a2s .  c o m*/
 *
 * @param bundle The bundle to convert
 * @return String representation of bundle
 */
public static String toString(Bundle bundle) {
    if (bundle == null) {
        return null;
    }
    StringBuilder stringBuilder = new StringBuilder();
    for (String key : bundle.keySet()) {
        Object value = bundle.get(key);
        stringBuilder.append(
                String.format("%s %s (%s)\n", key, value, value == null ? "null" : value.getClass().getName()));
    }
    return stringBuilder.substring(0, stringBuilder.length() - 1);
}

From source file:Main.java

public static void printExtras(Intent i) {
    if (i == null) {
        return;/*w ww .jav  a2  s.  co m*/
    }
    Bundle bundle = i.getExtras();
    if (bundle == null) {
        return;
    }
    Log.d("INTENT_EXTRAS", "++++ Printing extras: +++");
    for (String key : bundle.keySet()) {
        Object value = bundle.get(key);
        Log.d("INTENT_EXTRAS", String.format("%s %s (%s)", key, value.toString(), value.getClass().getName()));
    }
}

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);
        }// w  w  w  . j a va2s  . c om
    }
    return persistableBundle;
}

From source file:net.heroicefforts.viable.android.rep.it.auth.Authenticate.java

/**
 * Attempts to authenticate the user using a pre-existing stored authentication token.  If an account exists, but no such token 
 * exists, then the user will be prompted by the account authenticator to re-enter their Google credentials to generate the new token.
 * /* w w w  .  ja  v  a2 s .  c o  m*/
 * @param act the calling activity
 * @return the authentication token for the requested service or null if there is no Google Account.
 * @throws AuthenticatorException if an error occurs during authentication.
 * @throws OperationCanceledException
 * @throws IOException
 */
public static String authenticate(Activity act, String serviceCode)
        throws AuthenticatorException, OperationCanceledException, IOException {
    AccountManager mgr = AccountManager.get(act);
    Account[] accts = mgr.getAccountsByType(GCLAccountAuthenticator.ACCT_TYPE);
    if (accts.length > 0) {
        Account acct = accts[0];
        AccountManagerFuture<Bundle> accountManagerFuture = mgr.getAuthToken(acct, serviceCode, null, act, null,
                null);
        Bundle authTokenBundle = accountManagerFuture.getResult();
        String authToken = authTokenBundle.get(AccountManager.KEY_AUTHTOKEN).toString();

        return authToken;
    } else {
        Log.e(TAG, "No google accounts registered for this device.");
        return null;
    }
}

From source file:Main.java

public static JSONObject toJSON(Bundle object) {

    JSONObject jsonObject = new JSONObject();

    for (String key : object.keySet()) {
        try {/*from   w ww  .  ja va 2 s .c  o  m*/
            jsonObject.put(key, object.get(key));
        } catch (JSONException je) {
        }
    }
    return jsonObject;
}