List of usage examples for android.os Bundle getString
@Nullable
public String getString(@Nullable String key)
From source file:com.facebook.AppLinkData.java
private static AppLinkData createFromAlApplinkData(Intent intent) { Bundle applinks = intent.getBundleExtra(BUNDLE_AL_APPLINK_DATA_KEY); if (applinks == null) { return null; }//from w w w . j av a 2s . c o m AppLinkData appLinkData = new AppLinkData(); appLinkData.targetUri = intent.getData(); if (appLinkData.targetUri == null) { String targetUriString = applinks.getString(METHOD_ARGS_TARGET_URL_KEY); if (targetUriString != null) { appLinkData.targetUri = Uri.parse(targetUriString); } } appLinkData.argumentBundle = applinks; appLinkData.arguments = null; Bundle refererData = applinks.getBundle(ARGUMENTS_REFERER_DATA_KEY); if (refererData != null) { appLinkData.ref = refererData.getString(REFERER_DATA_REF_KEY); } return appLinkData; }
From source file:com.ble.facebook.Util.java
/** * Generate the multi-part post body providing the parameters and boundary * string/*from ww w . j av a2s . co 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"); } Log.d("encodePostBody", sb.toString()); return sb.toString(); }
From source file:karroo.app.test.facebook.Util.java
/** * Generate the multi-part post body providing the parameters and boundary * string//from w w w . j av a2 s . c om * * @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) { if (parameters.get(key) instanceof byte[]) { 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.groupme.sdk.util.HttpUtils.java
public static String encodeParams(Bundle params) { if (params == null || params.isEmpty()) { return ""; }//from w ww .j av a2 s . co m StringBuilder sb = new StringBuilder(); boolean first = true; for (String key : params.keySet()) { if (first) { first = false; } else { sb.append("&"); } try { sb.append(URLEncoder.encode(key, Constants.UTF_8)).append("=") .append(URLEncoder.encode(params.getString(key), Constants.UTF_8)); } catch (UnsupportedEncodingException e) { Log.e(Constants.LOG_TAG, "Unsupported encoding: " + e.toString()); } } return sb.toString(); }
From source file:com.google.sample.castcompanionlibrary.utils.Utils.java
/** * Builds and returns a {@link MediaInfo} that was wrapped in a {@link Bundle} by * <code>fromMediaInfo</code>. * * @param wrapper/* w ww. j a va 2s . c om*/ * @return * @see <code>fromMediaInfo()</code> */ 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) { 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 != null && 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); } } return 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).setStreamDuration(wrapper.getLong(KEY_STREAM_DURATION)).build(); }
From source file:cn.bidaround.ytcore.kaixin.KaixinUtil.java
/** * key-value????&?URL??/* www . j a v a2 s . c om*/ * * @param parameters * key-value?? * @return &?URL? */ @SuppressWarnings("deprecation") public static String encodeUrl(Bundle parameters) { if (parameters == null) { return ""; } StringBuilder sb = new StringBuilder(); boolean first = true; for (String key : parameters.keySet()) { if (first) first = false; else sb.append("&"); if (parameters.getString(key) != null) { sb.append(URLEncoder.encode(key) + "=" + URLEncoder.encode(parameters.getString(key))); } } return sb.toString(); }
From source file:cz.muni.fi.japanesedictionary.entity.JapaneseCharacter.java
/** * Creates new instance of JapaneseCharacter from saved instance in given bundle. * // w w w. ja va2 s.c om * @param bundle bundle with saved JapaneseCharacter * @return returns new instance of JapaneseCharacter or null if bundle is null */ public static JapaneseCharacter newInstanceFromBundle(Bundle bundle) { if (bundle == null) { return null; } JapaneseCharacter japaneseCharacter = new JapaneseCharacter(); japaneseCharacter.setLiteral(bundle.getString(SAVE_CHARACTER_LITERAL)); japaneseCharacter.setRadicalClassic(bundle.getInt(SAVE_CHARACTER_RADICAL, 0)); japaneseCharacter.setGrade(bundle.getInt(SAVE_CHARACTER_GRADE, 0)); japaneseCharacter.setStrokeCount(bundle.getInt(SAVE_CHARACTER_STROKE_COUNT, 0)); japaneseCharacter.setSkip(bundle.getString(SAVE_CHARACTER_SKIP)); japaneseCharacter.parseDicRef(bundle.getString(SAVE_CHARACTER_DIC_REF)); japaneseCharacter.parseRmGroupJaOn(bundle.getString(SAVE_CHARACTER_JA_ON)); japaneseCharacter.parseRmGroupJaKun(bundle.getString(SAVE_CHARACTER_JA_KUN)); japaneseCharacter.parseMeaningEnglish(bundle.getString(SAVE_CHARACTER_ENGLISH)); japaneseCharacter.parseMeaningFrench(bundle.getString(SAVE_CHARACTER_FRENCH)); /* * dutch, german, russian aren't in current kanjidict 2 */ japaneseCharacter.parseMeaningDutch(bundle.getString(SAVE_CHARACTER_DUTCH)); japaneseCharacter.parseMeaningGerman(bundle.getString(SAVE_CHARACTER_GERMAN)); japaneseCharacter.parseMeaningRussian(bundle.getString(SAVE_CHARACTER_RUSSIAN)); japaneseCharacter.parseNanori(bundle.getString(SAVE_CHARACTER_NANORI)); return japaneseCharacter.getLiteral() != null && japaneseCharacter.getLiteral().length() > 0 ? japaneseCharacter : null; }
From source file:com.facebook.notifications.NotificationsManager.java
/** * Present a {@link Notification} to be presented from a GCM push bundle. * <p/>// ww w .ja va2s . c o m * This does not present a notification immediately, instead it caches the assets from the * notification bundle, and then presents a notification to the user. This allows for a smoother * interaction without loading indicators for the user. * <p/> * Note that only one notification can be created for a specific push bundle, should you attempt * to present a new notification with the same payload bundle as an existing notification, it will * replace and update the old notification. * * @param context The context to send the notification from * @param notificationBundle The content of the push notification * @param launcherIntent The launcher intent that contains your Application's activity. * This will be modified with the FLAG_ACTIVITY_CLEAR_TOP and * FLAG_ACTIVITY_SINGLE_TOP flags, in order to properly show the * notification in an already running application. * <p/> * Should you not want this behavior, you may use the notificationExtender * parameter to customize the contentIntent of the notification before * presenting it. * @param notificationExtender A nullable argument that allows you to customize the notification * before displaying it. Use this to configure Icons, text, sounds, * etc. before we pass the notification off to the OS. */ public static boolean presentNotification(@NonNull final Context context, @NonNull final Bundle notificationBundle, @NonNull final Intent launcherIntent, @Nullable final NotificationExtender notificationExtender) { final JSONObject alert; final int payloadHash; try { String payload = notificationBundle.getString(CARD_PAYLOAD_KEY); if (payload == null) { return false; } payloadHash = payload.hashCode(); JSONObject payloadObject = new JSONObject(payload); alert = payloadObject.optJSONObject("alert") != null ? payloadObject.optJSONObject("alert") : new JSONObject(); } catch (JSONException ex) { Log.e(LOG_TAG, "Error while parsing notification bundle JSON", ex); return false; } final boolean[] success = new boolean[1]; final Thread backgroundThread = new Thread(new Runnable() { @Override public void run() { Looper.prepare(); prepareCard(context, notificationBundle, new PrepareCallback() { @Override public void onPrepared(@NonNull Intent presentationIntent) { Intent contentIntent = new Intent(launcherIntent); contentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); contentIntent.putExtra(EXTRA_PAYLOAD_INTENT, presentationIntent); NotificationManager manager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification.Builder builder = new Notification.Builder(context) .setSmallIcon(android.R.drawable.ic_dialog_alert) .setContentTitle(alert.optString("title")).setContentText(alert.optString("body")) .setAutoCancel(true) .setContentIntent(PendingIntent.getActivity(context.getApplicationContext(), payloadHash, contentIntent, PendingIntent.FLAG_ONE_SHOT)); if (notificationExtender != null) { builder = notificationExtender.extendNotification(builder); } manager.notify(NOTIFICATION_TAG, payloadHash, builder.getNotification()); success[0] = true; Looper.myLooper().quit(); } @Override public void onError(@NonNull Exception exception) { Log.e(LOG_TAG, "Error while preparing card", exception); Looper.myLooper().quit(); } }); Looper.loop(); } }); backgroundThread.start(); try { backgroundThread.join(); } catch (InterruptedException ex) { Log.e(LOG_TAG, "Failed to wait for background thread", ex); return false; } return success[0]; }
From source file:net.neoturbine.autolycus.internal.BusTimeAPI.java
/** * Requests the XML data for a given action and parameters. Matches the * <code>system</code> input with a hard-coded internal list to know which * server to use. Note that this MUST not be run in the UI thread. * //w w w.j a v a 2 s . c om * @param context * Currently unused, but needed for analytics. * @param verb * The string in the last part of the Base URL within the API * documentation. * @param system * One of the internally supported transit systems. * @param params * a Bundle containing the parameters to be passed within its * extras. * @return an XmlPullParser with the XML tree resulting from this API call. * * @throws ClientProtocolException * @throws IOException * @throws XmlPullParserException */ private static XmlPullParser loadData(Context context, String verb, String system, Bundle params) throws ClientProtocolException, IOException, XmlPullParserException { ArrayList<NameValuePair> qparams = new ArrayList<NameValuePair>(); if (params != null) { for (String name : params.keySet()) { qparams.add(new BasicNameValuePair(name, params.getString(name))); } } String server = ""; String key = ""; if (system.equals("Chicago Transit Authority")) { server = "www.ctabustracker.com"; key = "HeDbySM4CUDgRDsrGnRGZmD6K"; } else if (system.equals("Ohio State University TRIP")) { server = "trip.osu.edu"; key = "auixft7SWR3pWAcgkQfnfJpXt"; } else if (system.equals("MTA New York City Transit")) { server = "bustime34.mta.info"; key = "t7YxRNCmvVCfrZzrcMFeYegjp"; } qparams.add(new BasicNameValuePair("key", key)); // assemble the url URI uri; try { uri = URIUtils.createURI("http", // Protocol server, // server 80, // specified in API documentation "/bustime/api/v1/" + verb, // path URLEncodedUtils.format(qparams, "UTF-8"), null); } catch (URISyntaxException e) { // shouldn't happen throw new RuntimeException(e); } // assemble our request HttpClient httpClient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(uri); Log.i(TAG, "Retrieving " + httpget.getURI().toString()); // from localytics recordEvent(context,system,verb,false); // ah, the blocking HttpResponse response = httpClient.execute(httpget); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { throw new RuntimeException(response.getStatusLine().toString()); } InputStream content = response.getEntity().getContent(); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); XmlPullParser xpp = factory.newPullParser(); xpp.setInput(content, null); return xpp; }
From source file:com.ds.kaixin.Util.java
/** * key-value&URL//from w w w.j a v a2s. co m * * @param parameters * key-value * @return &URL */ public static String encodeUrl(Bundle parameters) { if (parameters == null) { return ""; } 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(); }