List of usage examples for android.os Bundle Bundle
public Bundle()
From source file:com.geozen.demo.foursquare.jiramot.Util.java
/** * Connect to an HTTP URL and return the response as a string. * //from w w w . java 2 s. c om * Note that the HTTP method override is used on non-GET requests. (i.e. * requests are made as "POST" with method specified in the body). * * @param url * - the resource to open: must be a welformed URL * @param method * - the HTTP method to use ("GET", "POST", etc.) * @param params * - the query parameter for the URL (e.g. access_token=foo) * @return the URL contents as a String * @throws MalformedURLException * - if the URL format is invalid * @throws IOException * - if a network problem occurs */ public static String openUrl(String url, String method, Bundle params) throws MalformedURLException, IOException { // random string as boundary for multi-part http post String strBoundary = "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f"; String endLine = "\r\n"; OutputStream os; if (method.equals("GET")) { url = url + "?" + encodeUrl(params); } Log.d("Foursquare-Util", method + " URL: " + url); HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestProperty("User-Agent", System.getProperties().getProperty("http.agent") + " GeoZen"); if (!method.equals("GET")) { Bundle dataparams = new Bundle(); for (String key : params.keySet()) { if (params.getByteArray(key) != null) { dataparams.putByteArray(key, params.getByteArray(key)); } } // use method override if (!params.containsKey("method")) { params.putString("method", method); } if (params.containsKey("access_token")) { String decoded_token = URLDecoder.decode(params.getString("access_token")); params.putString("access_token", decoded_token); } conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + strBoundary); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestProperty("Connection", "Keep-Alive"); conn.connect(); os = new BufferedOutputStream(conn.getOutputStream()); os.write(("--" + strBoundary + endLine).getBytes()); os.write((encodePostBody(params, strBoundary)).getBytes()); os.write((endLine + "--" + strBoundary + endLine).getBytes()); if (!dataparams.isEmpty()) { for (String key : dataparams.keySet()) { os.write(("Content-Disposition: form-data; filename=\"" + key + "\"" + endLine).getBytes()); os.write(("Content-Type: content/unknown" + endLine + endLine).getBytes()); os.write(dataparams.getByteArray(key)); os.write((endLine + "--" + strBoundary + endLine).getBytes()); } } os.flush(); } String response = ""; try { response = read(conn.getInputStream()); } catch (FileNotFoundException e) { // Error Stream contains JSON that we can parse to a FB error response = read(conn.getErrorStream()); } return response; }
From source file:com.sample.facebook.Util.java
/** * Connect to an HTTP URL and return the response as a string. * //ww w . j a va 2 s .c o m * Note that the HTTP method override is used on non-GET requests. (i.e. * requests are made as "POST" with method specified in the body). * * @param url - the resource to open: must be a welformed URL * @param method - the HTTP method to use ("GET", "POST", etc.) * @param params - the query parameter for the URL (e.g. access_token=foo) * @return the URL contents as a String * @throws MalformedURLException - if the URL format is invalid * @throws IOException - if a network problem occurs */ public static String openUrl(String url, String method, Bundle params) throws MalformedURLException, IOException { // random string as boundary for multi-part http post String strBoundary = "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f"; String endLine = "\r\n"; OutputStream os; if (method.equals("GET")) { url = url + "?" + encodeUrl(params); } Log.d("Facebook-Util", method + " URL: " + url); //url+="&fields=email"; HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestProperty("User-Agent", System.getProperties().getProperty("http.agent") + " FacebookAndroidSDK"); if (!method.equals("GET")) { Bundle dataparams = new Bundle(); for (String key : params.keySet()) { if (params.getByteArray(key) != null) { dataparams.putByteArray(key, params.getByteArray(key)); } } // use method override if (!params.containsKey("method")) { params.putString("method", method); } if (params.containsKey("access_token")) { String decoded_token = URLDecoder.decode(params.getString("access_token")); params.putString("access_token", decoded_token); } conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + strBoundary); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestProperty("Connection", "Keep-Alive"); conn.setConnectTimeout(45000); conn.connect(); os = new BufferedOutputStream(conn.getOutputStream()); os.write(("--" + strBoundary + endLine).getBytes()); os.write((encodePostBody(params, strBoundary)).getBytes()); os.write((endLine + "--" + strBoundary + endLine).getBytes()); if (!dataparams.isEmpty()) { for (String key : dataparams.keySet()) { os.write(("Content-Disposition: form-data; filename=\"" + key + "\"" + endLine).getBytes()); os.write(("Content-Type: content/unknown" + endLine + endLine).getBytes()); os.write(dataparams.getByteArray(key)); os.write((endLine + "--" + strBoundary + endLine).getBytes()); } } os.flush(); } String response = ""; try { response = read(conn.getInputStream()); } catch (FileNotFoundException e) { // Error Stream contains JSON that we can parse to a FB error response = read(conn.getErrorStream()); } return response; }
From source file:com.facebook.Util.java
/** * Connect to an HTTP URL and return the response as a string. * * Note that the HTTP method override is used on non-GET requests. (i.e. * requests are made as "POST" with method specified in the body). * * @param url - the resource to open: must be a welformed URL * @param method - the HTTP method to use ("GET", "POST", etc.) * @param params - the query parameter for the URL (e.g. access_token=foo) * @return the URL contents as a String/* ww w . j av a 2 s. co m*/ * @throws MalformedURLException - if the URL format is invalid * @throws IOException - if a network problem occurs */ @SuppressWarnings("deprecation") public static String openUrl(String url, String method, Bundle params) throws MalformedURLException, IOException { // random string as boundary for multi-part http post String strBoundary = "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f"; String endLine = "\r\n"; OutputStream os; if (method.equals("GET")) { url = url + "?" + encodeUrl(params); } Log.d("Facebook-Util", method + " URL: " + url); HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestProperty("User-Agent", System.getProperties().getProperty("http.agent") + " FacebookAndroidSDK"); if (!method.equals("GET")) { Bundle dataparams = new Bundle(); for (String key : params.keySet()) { if (params.getByteArray(key) != null) { dataparams.putByteArray(key, params.getByteArray(key)); } } // use method override if (!params.containsKey("method")) { params.putString("method", method); } if (params.containsKey("access_token")) { String decoded_token = URLDecoder.decode(params.getString("access_token")); params.putString("access_token", decoded_token); } conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + strBoundary); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestProperty("Connection", "Keep-Alive"); conn.connect(); os = new BufferedOutputStream(conn.getOutputStream()); os.write(("--" + strBoundary + endLine).getBytes()); os.write((encodePostBody(params, strBoundary)).getBytes()); os.write((endLine + "--" + strBoundary + endLine).getBytes()); if (!dataparams.isEmpty()) { for (String key : dataparams.keySet()) { os.write(("Content-Disposition: form-data; filename=\"" + key + "\"" + endLine).getBytes()); os.write(("Content-Type: content/unknown" + endLine + endLine).getBytes()); os.write(dataparams.getByteArray(key)); os.write((endLine + "--" + strBoundary + endLine).getBytes()); } } os.flush(); } String response = ""; try { response = read(conn.getInputStream()); } catch (FileNotFoundException e) { // Error Stream contains JSON that we can parse to a FB error response = read(conn.getErrorStream()); } return response; }
From source file:com.skubit.android.billing.BillingServiceBinder.java
@Override public Bundle getBuyIntent(int apiVersion, String userId, String packageName, String sku, String type, String developerPayload) throws RemoteException { Bundle bundle = new Bundle(); if (TextUtils.isEmpty(packageName) || TextUtils.isEmpty(sku) || TextUtils.isEmpty(type)) { Log.d(TAG, "Missing required parameter"); bundle.putInt("RESPONSE_CODE", BillingResponseCodes.RESULT_DEVELOPER_ERROR); return bundle; }/*ww w . j a va 2 s. c om*/ if (apiVersion != 1) { Log.d(TAG, "Unsupported API: " + apiVersion); bundle.putInt("RESPONSE_CODE", BillingResponseCodes.RESULT_BILLING_UNAVAILABLE); return bundle; } if (!isValidType(type)) { Log.d(TAG, "Incorrect billing type: " + type); bundle.putInt("RESPONSE_CODE", BillingResponseCodes.RESULT_BILLING_UNAVAILABLE); return bundle; } int packValidate = validatePackageIsOwnedByCaller(packageName); if (packValidate != BillingResponseCodes.RESULT_OK) { Log.d(TAG, "Package is not owned by caller"); bundle.putInt("RESPONSE_CODE", packValidate); return bundle; } if (!hasAccess(userId, packageName)) { Log.d(TAG, "User account not configured"); bundle.putInt("RESPONSE_CODE", BillingResponseCodes.RESULT_USER_ACCESS); return bundle; } /** * DO we already own this product? method: userId, packageName, * productId bundle.putInt("RESPONSE_CODE", * BillingResponseCodes.RESULT_ITEM_ALREADY_OWNED) */ Intent purchaseIntent = null; if ("inapp".equals(type)) { purchaseIntent = makePurchaseIntent(apiVersion, userId, packageName, sku, developerPayload, type); } if (purchaseIntent == null) { bundle.putInt("RESPONSE_CODE", BillingResponseCodes.RESULT_DEVELOPER_ERROR); return bundle; } Utils.changeAccount(mContext, userId); PendingIntent pending = PendingIntent.getActivity(mContext, (sku + userId).hashCode(), purchaseIntent, 0); bundle.putParcelable("BUY_INTENT", pending); bundle.putInt("RESPONSE_CODE", BillingResponseCodes.RESULT_OK); return bundle; }
From source file:com.kaixin.connect.Util.java
/** * http/*from ww w . j a v a 2 s. c om*/ * * @param context * * @param requestURL * * @param httpMethod * GET POST * @param params * key-valuekeyvalueStringbyte[] * @param photos * key-value keyfilename * valueInputStreambyte[] * InputStreamopenUrl * @return JSON * @throws IOException */ public static String openUrl(Context context, String requestURL, String httpMethod, Bundle params, Map<String, Object> photos) throws IOException { OutputStream os; if (httpMethod.equals("GET")) { requestURL = requestURL + "?" + encodeUrl(params); } URL url = new URL(requestURL); HttpsURLConnection conn = (HttpsURLConnection) getConnection(context, url); conn.setRequestProperty("User-Agent", System.getProperties().getProperty("http.agent") + " KaixinAndroidSDK"); conn.setDoInput(true); conn.setUseCaches(false); conn.setRequestProperty("Connection", "close"); conn.setRequestProperty("Charsert", "UTF-8"); if (!httpMethod.equals("GET")) { Bundle dataparams = new Bundle(); for (String key : params.keySet()) { if (params.getByteArray(key) != null) { dataparams.putByteArray(key, params.getByteArray(key)); } } String BOUNDARY = Util.md5(String.valueOf(System.currentTimeMillis())); // String endLine = "\r\n"; conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + BOUNDARY); conn.connect(); os = new BufferedOutputStream(conn.getOutputStream()); os.write(("--" + BOUNDARY + endLine).getBytes()); os.write((encodePostBody(params, BOUNDARY)).getBytes()); os.write((endLine + "--" + BOUNDARY + endLine).getBytes()); if (!dataparams.isEmpty()) { for (String key : dataparams.keySet()) { os.write(("Content-Disposition: form-data; name=\"" + key + "\"" + endLine).getBytes()); os.write(("Content-Type: content/unknown" + endLine + endLine).getBytes()); os.write(dataparams.getByteArray(key)); os.write((endLine + "--" + BOUNDARY + endLine).getBytes()); } } if (photos != null && !photos.isEmpty()) { for (String key : photos.keySet()) { Object obj = photos.get(key); if (obj instanceof InputStream) { InputStream is = (InputStream) obj; try { os.write(("Content-Disposition: form-data; name=\"pic\";filename=\"" + key + "\"" + endLine).getBytes()); os.write(("Content-Type:application/octet-stream\r\n\r\n").getBytes()); byte[] data = new byte[UPLOAD_BUFFER_SIZE]; int nReadLength = 0; while ((nReadLength = is.read(data)) != -1) { os.write(data, 0, nReadLength); } os.write((endLine + "--" + BOUNDARY + endLine).getBytes()); } finally { try { if (null != is) { is.close(); } } catch (Exception e) { Log.e(LOG_TAG, "Exception on closing input stream", e); } } } else if (obj instanceof byte[]) { byte[] byteArray = (byte[]) obj; os.write(("Content-Disposition: form-data; name=\"pic\";filename=\"" + key + "\"" + endLine) .getBytes()); os.write(("Content-Type:application/octet-stream\r\n\r\n").getBytes()); os.write(byteArray); os.write((endLine + "--" + BOUNDARY + endLine).getBytes()); } else { Log.e(LOG_TAG, ""); } } } os.flush(); } String response = ""; try { response = read(conn.getInputStream()); } catch (FileNotFoundException e) { response = read(conn.getErrorStream()); } return response; }
From source file:com.facebook.share.internal.LegacyNativeDialogParameters.java
private static Bundle createBaseParameters(ShareContent content, boolean dataErrorsFatal) { Bundle params = new Bundle(); Utility.putUri(params, ShareConstants.LEGACY_LINK, content.getContentUrl()); Utility.putNonEmptyString(params, ShareConstants.LEGACY_PLACE_TAG, content.getPlaceId()); Utility.putNonEmptyString(params, ShareConstants.LEGACY_REF, content.getRef()); params.putBoolean(ShareConstants.LEGACY_DATA_FAILURES_FATAL, dataErrorsFatal); List<String> peopleIds = content.getPeopleIds(); if (!Utility.isNullOrEmpty(peopleIds)) { params.putStringArrayList(ShareConstants.LEGACY_FRIEND_TAGS, new ArrayList<>(peopleIds)); }// w w w . j a v a2 s . c om return params; }
From source file:com.nextgis.firereporter.HttpGetter.java
@Override protected Void doInBackground(String... urls) { if (IsNetworkAvailible(mContext)) { try {//from ww w . j av a2 s . c o m String sURL = urls[0]; httpget = new HttpGet(sURL); Log.d("MainActivity", "HTTPGet URL " + sURL); if (urls.length > 1) { httpget.setHeader("Cookie", urls[1]); } //TODO: move timeouts to parameters HttpParams httpParameters = new BasicHttpParams(); int timeoutConnection = 1500; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. int timeoutSocket = 3000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); HttpClient Client = new DefaultHttpClient(httpParameters); HttpResponse response = Client.execute(httpget); //ResponseHandler<String> responseHandler = new BasicResponseHandler(); //mContent = Client.execute(httpget, responseHandler); HttpEntity entity = response.getEntity(); Bundle bundle = new Bundle(); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { bundle.putBoolean(GetFiresService.ERROR, false); mContent = EntityUtils.toString(entity); bundle.putString(GetFiresService.JSON, mContent); } else { bundle.putBoolean(GetFiresService.ERROR, true); bundle.putString(GetFiresService.ERR_MSG, response.getStatusLine().getStatusCode() + ": " + response.getStatusLine().getReasonPhrase()); } bundle.putInt(GetFiresService.SOURCE, mnType); Message msg = new Message(); msg.setData(bundle); if (mEventReceiver != null) { mEventReceiver.sendMessage(msg); } } catch (ClientProtocolException e) { mError = e.getMessage(); cancel(true); } catch (IOException e) { mError = e.getMessage(); cancel(true); } } else { Bundle bundle = new Bundle(); bundle.putBoolean(GetFiresService.ERROR, true); bundle.putString(GetFiresService.ERR_MSG, mContext.getString(R.string.noNetwork)); bundle.putInt(GetFiresService.SOURCE, mnType); Message msg = new Message(); msg.setData(bundle); if (mEventReceiver != null) { mEventReceiver.sendMessage(msg); } } return null; }
From source file:com.cloudbees.gasp.activity.GaspRESTLoaderActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set main content view for Gasp! Reviews setContentView(R.layout.gasp_review_activity); // Use the Fragments API to display review data FragmentManager fm = getFragmentManager(); ListFragment list = (ListFragment) fm.findFragmentById(R.id.gasp_review_content); if (list == null) { list = new ListFragment(); FragmentTransaction ft = fm.beginTransaction(); ft.add(R.id.gasp_review_content, list); ft.commit();//from www .ja v a 2s . c om } // Array adapter provides access to the review list data mAdapter = new ArrayAdapter<String>(this, R.layout.gasp_review_list); list.setListAdapter(mAdapter); // Load shared preferences from res/xml/preferences.xml (first time only) // Subsequent activations will use the saved shared preferences from the device PreferenceManager.setDefaultValues(this, R.xml.preferences, false); SharedPreferences gaspSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); Log.i(TAG, "Using Gasp Server URI: " + gaspSharedPreferences.getString("gasp_endpoint_uri", "")); Uri gaspReviewsUri = Uri.parse(gaspSharedPreferences.getString("gasp_endpoint_uri", "")); // Loader arguments: LoaderManager will maintain the state of our Loaders // and reload if necessary. Bundle args = new Bundle(); Bundle params = new Bundle(); args.putParcelable(ARGS_URI, gaspReviewsUri); args.putParcelable(ARGS_PARAMS, params); // Initialize the Loader. getLoaderManager().initLoader(LOADER_GASP_REVIEWS, args, this); // Use gasp-mongo REST service new ReviewsRequest().execute(); try { LocationsRequest locations = new LocationsRequest( new SpatialQuery(new Location(-122.1139858, 37.3774655), 0.005)); List<GeoLocation> locationList = locations.execute().get(); for (GeoLocation geoLocation : locationList) { Log.i(TAG, geoLocation.getName()); Log.i(TAG, " " + geoLocation.getFormattedAddress()); Log.i(TAG, " " + String.valueOf(geoLocation.getLocation().getLng())); Log.i(TAG, " " + String.valueOf(geoLocation.getLocation().getLat())); } } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage()); } }
From source file:it.openyoureyes.test.panoramio.Panoramio.java
public List<GeoItem> examinePanoramio(Location current, double distance, Drawable myImage, Intent intent) { ArrayList<GeoItem> result = new ArrayList<GeoItem>(); /*/*from www.j a va 2 s . co m*/ * var requiero_fotos = new Json.Remote( * "http://www.panoramio.com/map/get_panoramas.php?order=popularity& * set= * full&from=0&to=10&minx=-5.8&miny=42.59&maxx=-5.5&maxy=42.65&size= * medium " */ Location loc1 = new Location("test"); Location loc2 = new Location("test_"); AbstractGeoItem.calcDestination(current.getLatitude(), current.getLongitude(), 225, distance / 2, loc1); AbstractGeoItem.calcDestination(current.getLatitude(), current.getLongitude(), 45, distance / 2, loc2); try { URL url = new URL( "http://www.panoramio.com/map/get_panoramas.php?order=popularity&set=full&from=0&to=10&minx=" + loc1.getLongitude() + "&miny=" + loc1.getLatitude() + "&maxx=" + loc2.getLongitude() + "&maxy=" + loc2.getLatitude() + "&size=thumbnail"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoInput(true); conn.connect(); InputStream is = conn.getInputStream(); String line; BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuffer buf = new StringBuffer(); while ((line = reader.readLine()) != null) { buf.append(line + " "); } reader.close(); is.close(); conn.disconnect(); // while (is.read(buffer) != -1); String jsontext = buf.toString(); Log.d("Json Panoramio", jsontext); JSONObject entrie = new JSONObject(jsontext); JSONArray arr = entrie.getJSONArray("photos"); for (int i = 0; i < arr.length(); i++) { JSONObject panoramioObj = arr.getJSONObject(i); double longitude = panoramioObj.getDouble("longitude"); double latitude = panoramioObj.getDouble("latitude"); String urlFoto = panoramioObj.getString("photo_file_url"); String idFoto = panoramioObj.getString("photo_id"); Bundle bu = intent.getExtras(); if (bu == null) bu = new Bundle(); bu.putString("id", idFoto); intent.replaceExtras(bu); BitmapDrawable bb = new BitmapDrawable(downloadFile(urlFoto)); PanoramioItem item = new PanoramioItem(latitude, longitude, false, bb, intent); result.add(item); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } return result; }
From source file:net.reichholf.dreamdroid.fragment.abs.AbstractHttpFragment.java
@Override public Bundle getLoaderBundle(int loader) { Bundle args = new Bundle(); args.putSerializable("params", getHttpParams(DreamDroidHttpFragmentHelper.LOADER_DEFAULT_ID)); return args;//from www .j a v a 2 s . com }