List of usage examples for android.os Bundle getString
@Nullable
public String getString(@Nullable String key)
From source file:jp.mixi.android.sdk.util.UrlUtils.java
/** * Bundle???/* w ww .j a va 2 s. c om*/ * * @param params ?Bundle * @return ???String */ public static String encodeUrlForBundle(Bundle params) { if (params == null) { return ""; } StringBuilder builder = new StringBuilder(); boolean first = true; for (String key : params.keySet()) { if (first) { first = false; } else { builder.append(PARAM_SEPARATOR); } try { builder.append(URLEncoder.encode(key, HTTP.UTF_8) + EQUAL + URLEncoder.encode(params.getString(key), HTTP.UTF_8)); } catch (UnsupportedEncodingException e) { Log.e(TAG, e.getLocalizedMessage(), e); } } return builder.toString(); }
From source file:count.ly.messaging.TitaniumCountlyAndroidMessagingModule.java
private static String printBundle(Bundle bundle) { StringBuilder sb = new StringBuilder(); for (String key : bundle.keySet()) { sb.append("\nkey:" + key + ", value:" + bundle.getString(key)); }/*from ww w . j ava2 s.c o m*/ return sb.toString(); }
From source file:com.facebook.AccessToken.java
private static AccessToken createFromBundle(List<String> requestedPermissions, Bundle bundle, AccessTokenSource source, Date expirationBase, String applicationId) { String token = bundle.getString(ACCESS_TOKEN_KEY); Date expires = Utility.getBundleLongAsDate(bundle, EXPIRES_IN_KEY, expirationBase); String userId = bundle.getString(USER_ID_KEY); if (Utility.isNullOrEmpty(token) || (expires == null)) { return null; }/*from w w w . ja v a 2s.co m*/ return new AccessToken(token, applicationId, userId, requestedPermissions, null, source, expires, new Date()); }
From source file:de.geeksfactory.opacclient.OpacClient.java
public static List<SearchQuery> bundleToQuery(Bundle bundle) { if (bundle == null) { return null; }//from w w w . java2 s. com List<SearchQuery> query = new ArrayList<>(); for (String e : bundle.keySet()) { try { query.add(new SearchQuery(SearchField.fromJSON(new JSONObject(e)), bundle.getString(e))); } catch (JSONException e1) { e1.printStackTrace(); } } return query; }
From source file:com.google.android.libraries.cast.companionlibrary.utils.Utils.java
/** * Builds and returns a {@link MediaInfo} that was wrapped in a {@link Bundle} by * <code>mediaInfoToBundle</code>. It is assumed that the type of the {@link MediaInfo} is * {@code MediaMetaData.MEDIA_TYPE_MOVIE} * * @see <code>mediaInfoToBundle()</code> */// ww w .j av a 2 s .com public static MediaInfo bundleToMediaInfo(Bundle wrapper) { if (wrapper == null) { return null; } MediaMetadata metaData = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE); metaData.putString(MediaMetadata.KEY_SUBTITLE, wrapper.getString(MediaMetadata.KEY_SUBTITLE)); metaData.putString(MediaMetadata.KEY_TITLE, wrapper.getString(MediaMetadata.KEY_TITLE)); metaData.putString(MediaMetadata.KEY_STUDIO, wrapper.getString(MediaMetadata.KEY_STUDIO)); ArrayList<String> images = wrapper.getStringArrayList(KEY_IMAGES); if (images != null && !images.isEmpty()) { for (String url : images) { Uri uri = Uri.parse(url); metaData.addImage(new WebImage(uri)); } } String customDataStr = wrapper.getString(KEY_CUSTOM_DATA); JSONObject customData = null; if (!TextUtils.isEmpty(customDataStr)) { try { customData = new JSONObject(customDataStr); } catch (JSONException e) { LOGE(TAG, "Failed to deserialize the custom data string: custom data= " + customDataStr); } } List<MediaTrack> mediaTracks = null; if (wrapper.getString(KEY_TRACKS_DATA) != null) { try { JSONArray jsonArray = new JSONArray(wrapper.getString(KEY_TRACKS_DATA)); mediaTracks = new ArrayList<MediaTrack>(); if (jsonArray.length() > 0) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObj = (JSONObject) jsonArray.get(i); MediaTrack.Builder builder = new MediaTrack.Builder(jsonObj.getLong(KEY_TRACK_ID), jsonObj.getInt(KEY_TRACK_TYPE)); if (jsonObj.has(KEY_TRACK_NAME)) { builder.setName(jsonObj.getString(KEY_TRACK_NAME)); } if (jsonObj.has(KEY_TRACK_SUBTYPE)) { builder.setSubtype(jsonObj.getInt(KEY_TRACK_SUBTYPE)); } if (jsonObj.has(KEY_TRACK_CONTENT_ID)) { builder.setContentId(jsonObj.getString(KEY_TRACK_CONTENT_ID)); } if (jsonObj.has(KEY_TRACK_LANGUAGE)) { builder.setLanguage(jsonObj.getString(KEY_TRACK_LANGUAGE)); } if (jsonObj.has(KEY_TRACKS_DATA)) { builder.setCustomData(new JSONObject(jsonObj.getString(KEY_TRACKS_DATA))); } mediaTracks.add(builder.build()); } } } catch (JSONException e) { LOGE(TAG, "Failed to build media tracks from the wrapper bundle", e); } } MediaInfo.Builder mediaBuilder = new MediaInfo.Builder(wrapper.getString(KEY_URL)) .setStreamType(wrapper.getInt(KEY_STREAM_TYPE)).setContentType(wrapper.getString(KEY_CONTENT_TYPE)) .setMetadata(metaData).setCustomData(customData).setMediaTracks(mediaTracks); if (wrapper.containsKey(KEY_STREAM_DURATION) && wrapper.getLong(KEY_STREAM_DURATION) >= 0) { mediaBuilder.setStreamDuration(wrapper.getLong(KEY_STREAM_DURATION)); } return mediaBuilder.build(); }
From source file:air.com.snagfilms.cast.chromecast.utils.Utils.java
/** * Builds and returns a {@link MediaInfo} that was wrapped in a * {@link Bundle} by <code>fromMediaInfo</code>. * //from w w w . j a va2 s .c o m * @see <code>fromMediaInfo()</code> * @param wrapper * @return */ public static MediaInfo toMediaInfo(Bundle wrapper) { if (null == wrapper) { return null; } MediaMetadata metaData = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE); metaData.putString(MediaMetadata.KEY_SUBTITLE, wrapper.getString(MediaMetadata.KEY_SUBTITLE)); metaData.putString(MediaMetadata.KEY_TITLE, wrapper.getString(MediaMetadata.KEY_TITLE)); metaData.putString(MediaMetadata.KEY_STUDIO, wrapper.getString(MediaMetadata.KEY_STUDIO)); ArrayList<String> images = wrapper.getStringArrayList(KEY_IMAGES); if (null != images && !images.isEmpty()) { for (String url : images) { Uri uri = Uri.parse(url); metaData.addImage(new WebImage(uri)); } } String customDataStr = wrapper.getString(KEY_CUSTOM_DATA); JSONObject customData = null; if (!TextUtils.isEmpty(customDataStr)) { try { customData = new JSONObject(customDataStr); } catch (JSONException e) { Log.e(TAG, "Failed to deserialize the custom data string: custom data= " + customDataStr); } } return new MediaInfo.Builder(wrapper.getString(KEY_URL)).setStreamType(wrapper.getInt(KEY_STREAM_TYPE)) .setContentType(wrapper.getString(KEY_CONTENT_TYPE)).setMetadata(metaData).setCustomData(customData) .build(); }
From source file:br.com.ufc.palestrasufc.twitter.Util.java
/** * Generate the multi-part post body providing the parameters and boundary * string// ww w . j a v a 2 s . c o m * * @param parameters the parameters need to be posted * @param boundary the random string as boundary * @return a string of the post body */ 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"); } return sb.toString(); }
From source file:com.arellomobile.android.push.PushGCMIntentService.java
private static void generateBroadcast(Context context, Bundle extras) { Intent broadcastIntent = new Intent(); broadcastIntent.setAction(context.getPackageName() + ".action.PUSH_MESSAGE_RECEIVE"); broadcastIntent.putExtras(extras);/*from w w w .j a v a2 s .c o m*/ JSONObject dataObject = new JSONObject(); try { if (extras.containsKey("title")) { dataObject.put("title", extras.get("title")); } if (extras.containsKey("u")) { dataObject.put("userdata", new JSONObject(extras.getString("u"))); } } catch (JSONException e) { // pass } broadcastIntent.putExtra(BasePushMessageReceiver.DATA_KEY, dataObject.toString()); context.sendBroadcast(broadcastIntent, context.getPackageName() + ".permission.C2D_MESSAGE"); }
From source file:com.geekandroid.sdk.sample.JPushReceiver.java
private static String printBundle(Bundle bundle) { StringBuilder sb = new StringBuilder(); for (String key : bundle.keySet()) { if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) { sb.append("\nkey:" + key + ", value:" + bundle.getInt(key)); } else if (key.equals(JPushInterface.EXTRA_CONNECTION_CHANGE)) { sb.append("\nkey:" + key + ", value:" + bundle.getBoolean(key)); } else if (key.equals(JPushInterface.EXTRA_EXTRA)) { if (bundle.getString(JPushInterface.EXTRA_EXTRA).isEmpty()) { Log.i(TAG, "This message has no Extra data"); continue; }/*from ww w . java2 s . c om*/ try { JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA)); Iterator<String> it = json.keys(); while (it.hasNext()) { String myKey = it.next().toString(); sb.append("\nkey:" + key + ", value: [" + myKey + " - " + json.optString(myKey) + "]"); } } catch (JSONException e) { Log.e(TAG, "Get message extra JSON error!"); } } else { sb.append("\nkey:" + key + ", value:" + bundle.getString(key)); } } return sb.toString(); }
From source file:fb.android.Util.java
/** * Generate the multi-part post body providing the parameters and boundary * string//from w w w .j a v a 2 s . com * * @param parameters the parameters need to be posted * @param boundary the random string as boundary * @return a string of the post body */ 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"); } return sb.toString(); }