Example usage for android.os Bundle putString

List of usage examples for android.os Bundle putString

Introduction

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

Prototype

public void putString(@Nullable String key, @Nullable String value) 

Source Link

Document

Inserts a String value into the mapping of this Bundle, replacing any existing value for the given key.

Usage

From source file:com.pixmob.r2droid.SelectAccountActivity.java

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putString(STATE_SELECTED_ACCOUNT, selectedAccount);
}

From source file:com.amazon.adobepass.auth.AdobepassAuthentication.java

/**
 * Bundle to be sent on authorization failure
 *
 * @param statusCode status code of failure
 * @param bundle     Bundle to populate/*from  w  w  w.j av a2 s .  c o m*/
 * @param throwable  throwable thrown
 */
private void populateAuthorizationFailureBundle(int statusCode, Bundle bundle, Throwable throwable) {

    bundle.putInt(ResponseHandler.STATUS_CODE, statusCode);
    bundle.putString(AuthenticationConstants.ERROR_CATEGORY,
            AuthenticationConstants.AUTHORIZATION_ERROR_CATEGORY);
    bundle.putSerializable(AuthenticationConstants.ERROR_CAUSE, throwable);
}

From source file:com.amazon.adobepass.auth.AdobepassAuthentication.java

/**
 * Bundle to be sent on authentication failure
 *
 * @param statusCode status code of failure
 * @param bundle     Bundle to populate//w  w  w.  j  a va2  s .  c o m
 * @param throwable  throwable thrown
 */
private void populateAuthenticationFailureBundle(int statusCode, Bundle bundle, Throwable throwable) {

    bundle.putInt(ResponseHandler.STATUS_CODE, statusCode);
    bundle.putString(AuthenticationConstants.ERROR_CATEGORY,
            AuthenticationConstants.AUTHENTICATION_ERROR_CATEGORY);
    bundle.putSerializable(AuthenticationConstants.ERROR_CAUSE, throwable);
}

From source file:com.eutectoid.dosomething.picker.FriendPickerFragment.java

private GraphRequest createRequest(String userID, Set<String> extraFields) {
    AccessToken accessToken = AccessToken.getCurrentAccessToken();
    GraphRequest request = GraphRequest.newGraphPathRequest(accessToken,
            userID + friendPickerType.getRequestPath(), null);

    Set<String> fields = new HashSet<String>(extraFields);
    String[] requiredFields = new String[] { ID, NAME };
    fields.addAll(Arrays.asList(requiredFields));

    String pictureField = adapter.getPictureFieldSpecifier();
    if (pictureField != null) {
        fields.add(pictureField);/*  w ww  .  jav  a  2 s.co m*/
    }

    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);

    return request;
}

From source file:com.irccloud.android.activity.PastebinEditorActivity.java

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putString("paste_contents", paste.getText().toString());
    outState.putString("paste_id", pasteID);
    outState.putString("message", message.getText().toString());
    outState.putString("filename", filename.getText().toString());
    outState.putInt("tab", current_tab);
}

From source file:gov.wa.wsdot.android.wsdot.ui.FerriesRouteAlertsBulletinsFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Bundle b = new Bundle();
    Intent intent = new Intent(getActivity(), FerriesRouteAlertsBulletinDetailsActivity.class);
    b.putString("AlertFullTitle", routeAlertItems.get(position).getAlertFullTitle());
    b.putString("AlertPublishDate", routeAlertItems.get(position).getPublishDate());
    b.putString("AlertDescription", routeAlertItems.get(position).getAlertDescription());
    b.putString("AlertFullText", routeAlertItems.get(position).getAlertFullText());
    intent.putExtras(b);//  w  w w. jav a 2s  .  c  om
    startActivity(intent);
}

From source file:com.cloudbees.gasp.service.RESTService.java

@Override
protected void onHandleIntent(Intent intent) {
    // When an intent is received by this Service, this method
    // is called on a new thread.

    Uri action = intent.getData();//  w  w w.j a v a 2 s  . c  om
    Bundle extras = intent.getExtras();

    if (extras == null || action == null || !extras.containsKey(EXTRA_RESULT_RECEIVER)) {
        // Extras contain our ResultReceiver and data is our REST action.  
        // So, without these components we can't do anything useful.
        Log.e(TAG, "You did not pass extras or data with the Intent.");

        return;
    }

    // We default to GET if no verb was specified.
    int verb = extras.getInt(EXTRA_HTTP_VERB, GET);
    Bundle params = extras.getParcelable(EXTRA_PARAMS);
    ResultReceiver receiver = extras.getParcelable(EXTRA_RESULT_RECEIVER);

    try {
        // Here we define our base request object which we will
        // send to our REST service via HttpClient.
        HttpRequestBase request = null;

        // Let's build our request based on the HTTP verb we were
        // given.
        switch (verb) {
        case GET: {
            request = new HttpGet();
            attachUriWithQuery(request, action, params);
        }
            break;

        case DELETE: {
            request = new HttpDelete();
            attachUriWithQuery(request, action, params);
        }
            break;

        case POST: {
            request = new HttpPost();
            request.setURI(new URI(action.toString()));

            // Attach form entity if necessary. Note: some REST APIs
            // require you to POST JSON. This is easy to do, simply use
            // postRequest.setHeader('Content-Type', 'application/json')
            // and StringEntity instead. Same thing for the PUT case 
            // below.
            HttpPost postRequest = (HttpPost) request;

            if (params != null) {
                UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params));
                postRequest.setEntity(formEntity);
            }
        }
            break;

        case PUT: {
            request = new HttpPut();
            request.setURI(new URI(action.toString()));

            // Attach form entity if necessary.
            HttpPut putRequest = (HttpPut) request;

            if (params != null) {
                UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params));
                putRequest.setEntity(formEntity);
            }
        }
            break;
        }

        if (request != null) {
            HttpClient client = new DefaultHttpClient();

            // Let's send some useful debug information so we can monitor things
            // in LogCat.
            Log.d(TAG, "Executing request: " + verbToString(verb) + ": " + action.toString());

            // Finally, we send our request using HTTP. This is the synchronous
            // long operation that we need to run on this thread.
            HttpResponse response = client.execute(request);

            HttpEntity responseEntity = response.getEntity();
            StatusLine responseStatus = response.getStatusLine();
            int statusCode = responseStatus != null ? responseStatus.getStatusCode() : 0;

            // Our ResultReceiver allows us to communicate back the results to the caller. This
            // class has a method named send() that can send back a code and a Bundle
            // of data. ResultReceiver and IntentService abstract away all the IPC code
            // we would need to write to normally make this work.
            if (responseEntity != null) {
                Bundle resultData = new Bundle();
                resultData.putString(REST_RESULT, EntityUtils.toString(responseEntity));
                receiver.send(statusCode, resultData);
            } else {
                receiver.send(statusCode, null);
            }
        }
    } catch (URISyntaxException e) {
        Log.e(TAG, "URI syntax was incorrect. " + verbToString(verb) + ": " + action.toString(), e);
        receiver.send(0, null);
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, "A UrlEncodedFormEntity was created with an unsupported encoding.", e);
        receiver.send(0, null);
    } catch (ClientProtocolException e) {
        Log.e(TAG, "There was a problem when sending the request.", e);
        receiver.send(0, null);
    } catch (IOException e) {
        Log.e(TAG, "There was a problem when sending the request.", e);
        receiver.send(0, null);
    }
}

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/*from w  w  w.  j a  va  2s  . c  om*/
 * @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.mobli.android.AsyncMobliRunner.java

/**
 * Obtain public (shared) access_token asynchronously.
 * //  www.ja  va 2s  .  c om
 * @param listener
 *            Callback interface to notify the application when the request
 *            has completed.
 * @param state
 *            An arbitrary object used to identify the request when it
 *            returns to the callback. This has no effect on the request
 *            itself.
 */
public void obtainPublicToken(final RequestListener originalListener, final Object state) {
    RequestListener listener;
    Bundle params = new Bundle();
    params.putString("client_id", mobli.getClientId());
    params.putString("client_secret", mobli.getClientSecret());
    params.putString("grant_type", "client_credentials");
    params.putString("scope", "shared");

    listener = new RequestListener() {

        @Override
        public void onMobliError(MobliError e, Object state) {
            originalListener.onMobliError(e, state);
        }

        @Override
        public void onMalformedURLException(MalformedURLException e, Object state) {
            originalListener.onMalformedURLException(e, state);
        }

        @Override
        public void onIOException(IOException e, Object state) {
            originalListener.onIOException(e, state);
        }

        @Override
        public void onFileNotFoundException(FileNotFoundException e, Object state) {
            originalListener.onFileNotFoundException(e, state);
        }

        @Override
        public void onComplete(String response, Object state) {

            //store public token
            try {
                String publicAccessToken;
                JSONObject json = new JSONObject(response);
                publicAccessToken = json.getString(Mobli.TOKEN);
                mobli.setAccessToken(publicAccessToken);
            } catch (Exception e) {
                // do nothing
            }

            originalListener.onComplete(response, state);
        }
    };

    request(Mobli.AUTHORIZE_BASE_URL, "/shared", params, "POST", listener, state);
}