List of usage examples for android.os Bundle containsKey
public boolean containsKey(String key)
From source file:com.ble.facebook.Util.java
/** * Connect to an HTTP URL and return the response as a string. * /*from w w w . j a v a 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.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:ca.shoaib.ping.PingListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); // Restore the previously serialized activated item position. if (savedInstanceState != null && savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) { setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION)); }//from w ww .j a v a2 s . com }
From source file:com.sample.facebook.Util.java
/** * Connect to an HTTP URL and return the response as a string. * /*from www. ja va 2s. com*/ * 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:at.alladin.rmbt.android.fragments.result.QoSTestDetailPagerFragment.java
@SuppressWarnings("unchecked") @Override// w ww .j ava 2s.c om public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); //final Bundle args = getArguments(); if (savedInstanceState != null) { initPageIndex = savedInstanceState.getInt(OPTIONS_PAGE_INDEX, 0); if (savedInstanceState.containsKey(BUNDLE_QOS_RESULT_LIST)) { setQoSResultList((List<QoSServerResult>) ((Bundle) savedInstanceState) .getSerializable(BUNDLE_QOS_RESULT_LIST)); setQoSDescList((List<QoSServerResultDesc>) ((Bundle) savedInstanceState) .getSerializable(BUNDLE_QOS_DESC_LIST)); } } //DetailType detailType = DetailType.valueOf(args.getString(ARG_DETAIL_TYPE)); pagerAdapter = new QoSTestDetailPagerAdapter((RMBTMainActivity) getActivity(), resultList, descList); }
From source file:com.intravel.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//from w w w .j av a 2 s . c om * @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); } // else{ // 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.eutectoid.dosomething.picker.FriendPickerFragment.java
@Override public void setSettingsFromBundle(Bundle inState) { super.setSettingsFromBundle(inState); if (inState != null) { if (inState.containsKey(USER_ID_BUNDLE_KEY)) { setUserId(inState.getString(USER_ID_BUNDLE_KEY)); }// w w w. ja v a 2 s.com setMultiSelect(inState.getBoolean(MULTI_SELECT_BUNDLE_KEY, multiSelect)); if (inState.containsKey(FRIEND_PICKER_TYPE_KEY)) { try { friendPickerType = FriendPickerType.valueOf(inState.getString(FRIEND_PICKER_TYPE_KEY)); } catch (Exception e) { // NOOP } } } }
From source file:be.blinkt.openvpn.activities.MainActivity.java
private AppConfiguration getManagedConfiguration() { AppConfiguration appConf = new AppConfiguration(); RestrictionsManager myRestrictionsMgr = (RestrictionsManager) this .getSystemService(Context.RESTRICTIONS_SERVICE); Bundle appRestrictions = myRestrictionsMgr.getApplicationRestrictions(); String commonVPNConfiguration = null, userVPNConfiguration = null, allowedApps = null; if (appRestrictions.containsKey("CommonVPNConfiguration")) { commonVPNConfiguration = appRestrictions.getString("CommonVPNConfiguration"); System.out.println("CommonVPNConfiguration: " + commonVPNConfiguration); }/*from w ww . ja v a 2 s . c om*/ if (appRestrictions.containsKey("UserVPNConfiguration")) { userVPNConfiguration = appRestrictions.getString("UserVPNConfiguration"); System.out.println("UserVPNConfiguration: " + userVPNConfiguration); } if (appRestrictions.containsKey("AllowedApps")) { allowedApps = appRestrictions.getString("AllowedApps"); System.out.println("AllowedApps: " + allowedApps); } if (commonVPNConfiguration != null && userVPNConfiguration != null && allowedApps != null) { appConf.setAllowedApps(allowedApps); appConf.setCommonConfiguration(commonVPNConfiguration); appConf.setUserConfiguration(userVPNConfiguration); return appConf; } else return null; }
From source file:ca.ualberta.cmput301w14t08.geochan.fragments.PostFragment.java
/** * Resumes the fragment, updating the location and textview states accordingly. *//*from www . j ava 2s. co m*/ @Override public void onResume() { super.onResume(); Bundle args = getArguments(); if (args != null) { if (args.containsKey("LATITUDE") && args.containsKey("LONGITUDE")) { Button locButton = (Button) getActivity().findViewById(R.id.location_button); if (args.getString("LocationType") == "CURRENT_LOCATION") { locButton.setText("Location: Set"); } else { Double lat = args.getDouble("LATITUDE"); Double lon = args.getDouble("LONGITUDE"); geoLocation = new GeoLocation(lat, lon); String locationDescription = args.getString("locationDescription"); geoLocation.setLocationDescription(locationDescription); locButton.setText("Location: Set"); } } if (args.containsKey("IMAGE_THUMB") && args.containsKey("IMAGE_FULL")) { imageThumb = args.getParcelable("IMAGE_THUMB"); image = args.getParcelable("IMAGE_FULL"); } } }
From source file:app.hacked.ChallengeListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); // Restore the previously serialized activated item position. if (savedInstanceState != null && savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) { setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION)); }//from ww w.j a v a 2 s .c om if (getActivity().findViewById(R.id.ChallengeDetails) != null && savedInstanceState == null) { ChallengeWelcomeFragment fragment = new ChallengeWelcomeFragment(); getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.ChallengeDetails, fragment) .commit(); } getData(); }