Example usage for android.os Bundle getString

List of usage examples for android.os Bundle getString

Introduction

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

Prototype

@Nullable
public String getString(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:Main.java

/**
 * Get string from extra or from metadata.
 * /*  ww w .  j  a  va2 s. com*/
 * @param context
 * @param packagename
 * @param intent
 * @param extra
 * @param metadata
 * @return
 */
public static String getStringExtraOrMetadata(final Context context, final String packagename,
        final Intent intent, final String extra, final String metadata) {
    if (intent.hasExtra(extra) && intent.getStringExtra(extra) != null) {
        return intent.getStringExtra(extra);
    } else {
        //Try meta data of package
        Bundle md = null;
        try {
            md = context.getPackageManager().getApplicationInfo(packagename,
                    PackageManager.GET_META_DATA).metaData;
        } catch (NameNotFoundException e) {
            Log.e(TAG, "Package name not found", e);
        }

        if (md != null && !TextUtils.isEmpty(md.getString(metadata))) {
            return md.getString(metadata);
        } else {
            return "";
        }

    }
}

From source file:com.facebook.login.LoginMethodHandler.java

public static AccessToken createAccessTokenFromWebBundle(Collection<String> requestedPermissions, Bundle bundle,
        AccessTokenSource source, String applicationId) throws FacebookException {
    Date expires = Utility.getBundleLongAsDate(bundle, AccessToken.EXPIRES_IN_KEY, new Date());
    String token = bundle.getString(AccessToken.ACCESS_TOKEN_KEY);

    // With Login v4, we now get back the actual permissions granted, so update the permissions
    // to be the real thing
    String grantedPermissions = bundle.getString("granted_scopes");
    if (!Utility.isNullOrEmpty(grantedPermissions)) {
        requestedPermissions = new ArrayList<String>(Arrays.asList(grantedPermissions.split(",")));
    }/*from ww  w  .  j ava 2  s  .  c om*/
    String deniedPermissions = bundle.getString("denied_scopes");
    List<String> declinedPermissions = null;
    if (!Utility.isNullOrEmpty(deniedPermissions)) {
        declinedPermissions = new ArrayList<String>(Arrays.asList(deniedPermissions.split(",")));
    }

    if (Utility.isNullOrEmpty(token)) {
        return null;
    }

    String signed_request = bundle.getString("signed_request");
    String userId = getUserIDFromSignedRequest(signed_request);

    return new AccessToken(token, applicationId, userId, requestedPermissions, declinedPermissions, source,
            expires, new Date());
}

From source file:Main.java

public static String encodePostBody(Bundle parameters, String boundary) {
    if (parameters == null)
        return "";
    StringBuilder sb = new StringBuilder();

    for (String key : parameters.keySet()) {
        if (parameters.getByteArray(key) != null) {
            continue;
        }//from  w  w  w  . j a  va2  s  . co  m

        sb.append("Content-Disposition: form-data; name=\"" + key + "\"\r\n\r\n" + parameters.getString(key));
        sb.append("\r\n" + "--" + boundary + "\r\n");
    }

    return sb.toString();
}

From source file:Main.java

public static String encodeUrl(Bundle parameters) {
    if (parameters == null) {
        return "";
    }//  w w w .jav  a2 s . com

    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (String key : parameters.keySet()) {
        if (first)
            first = false;
        else
            sb.append("&");
        sb.append(URLEncoder.encode(key) + "=" + URLEncoder.encode(parameters.getString(key)));
    }
    return sb.toString();
}

From source file:com.google.android.apps.muzei.api.internal.SourceState.java

public static SourceState fromBundle(Bundle bundle) {
    SourceState state = new SourceState();
    Bundle artworkBundle = bundle.getBundle("currentArtwork");
    if (artworkBundle != null) {
        state.mCurrentArtwork = Artwork.fromBundle(artworkBundle);
    }//from  ww w .j a  va2  s . c  o  m
    state.mDescription = bundle.getString("description");
    state.mWantsNetworkAvailable = bundle.getBoolean("wantsNetworkAvailable");
    String[] commandsSerialized = bundle.getStringArray("userCommands");
    if (commandsSerialized != null && commandsSerialized.length > 0) {
        for (String s : commandsSerialized) {
            state.mUserCommands.add(UserCommand.deserialize(s));
        }
    }
    return state;
}

From source file:Main.java

public static String encodePostBody(Bundle parameters, String boundary) {
    if (parameters == null)
        return "";
    StringBuilder sb = new StringBuilder();

    for (String key : parameters.keySet()) {

        //         if (parameters.getByteArray(key) != null) {
        //            continue;
        //         }

        sb.append("Content-Disposition: form-data; name=\"" + key + "\"\r\n\r\n" + parameters.getString(key));
        sb.append("\r\n" + "--" + boundary + "\r\n");
    }//from   ww  w  .  ja v a  2s .  c o m

    return sb.toString();
}

From source file:com.scoreflex.ScoreflexGcmClient.java

protected static boolean onBroadcastReceived(Context context, Intent intent, int iconResource,
        Class<? extends Activity> activity) {
    Bundle extras = intent.getExtras();

    if (extras.isEmpty()) { // has effect of unparcelling Bundle
        return false;
    }/*from   w  w  w.ja  va2s  .  c o m*/
    String customDataJson = extras.getString(SCOREFLEX_CUSTOM_DATA_EXTRA_KEY);
    if (null == customDataJson) {
        return false;
    }

    try {

        JSONObject customData = new JSONObject(customDataJson);
        JSONObject data = customData.getJSONObject(SCOREFLEX_NOTIFICATION_EXTRA_KEY);
        JSONObject sfxData = data.optJSONObject("data");

        if (data.getInt("code") < Scoreflex.NOTIFICATION_TYPE_CHALLENGE_INVITATION) {
            return false;
        }
        String targetPlayerId = sfxData.optString("targetPlayerId");
        String loggedPlayerId = ScoreflexRestClient.getPlayerId(context);

        if (!targetPlayerId.equals(loggedPlayerId)) {
            return false;
        }
        PendingIntent pendingIntent = buildPendingIntent(data, context, activity);
        Notification notification = buildNotification(extras.getString("alert"), context, iconResource,
                pendingIntent);

        NotificationManager mNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(data.getInt("code"), notification);
        intent.removeExtra(SCOREFLEX_CUSTOM_DATA_EXTRA_KEY);
    } catch (JSONException e1) {

    }

    return false;
}

From source file:Main.java

public static String encodeUrl(Bundle parameters) {
    if (parameters == null) {
        return "";
    }//from  ww  w .j  a v  a2s.c om

    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (String key : parameters.keySet()) {
        if (first)
            first = false;
        else
            sb.append("&");
        sb.append(key + "=" + parameters.getString(key));
    }
    return sb.toString();
}

From source file:com.hybris.mobile.factory.barcode.IntentBarcodeFactory.java

/**
 * Get the associated IntentBarcode according to the intentType
 * //from ww  w .  j a va2 s  .  c  o m
 * @param intentType
 * @param intentExtras
 * @param activity
 * @return
 */
public static IntentBarcode getIntent(String intentType, Bundle intentExtras, Activity activity) {
    IntentBarcode intentBarcode = null;

    if (StringUtils.isNotEmpty(intentType)) {

        if (StringUtils.equals(DataConstants.INTENT_ORDER_DETAILS, intentType)) {
            intentBarcode = new OrderDetailsIntentBarcodeImpl(intentExtras.getString(DataConstants.ORDER_ID),
                    activity);
        }

    }

    return intentBarcode;
}

From source file:com.groupme.sdk.util.HttpUtils.java

public static List<NameValuePair> bundleToList(Bundle params) {
    List<NameValuePair> pairs = new ArrayList<NameValuePair>();

    /* TODO: URL encode the params. */
    for (String key : params.keySet()) {
        pairs.add(new BasicNameValuePair(key, params.getString(key)));
    }/*from   w  ww.  ja  v a  2 s  . c  o m*/

    return pairs;
}