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:ch.ethz.inf.vs.android.g54.a4.types.Building.java

/**
 * Asynchronously get free rooms based on floor and time constraints
 * A message will be dispatched to the handler informing of the status
 * In case of failure, the exception string is passed through the message key of the bundle
 * @param f Floor constraint//from  ww w . j av a  2  s  .  c o  m
 * @param start time constraint in quarter hours
 * @param end time constraint in quarter hours
 * @param handler Handler that will get the success/failure message with this object
 */
public void getFreeRoomsAsync(final Floor f, final Float start, final Float end, final Handler handler) {
    new Thread() {
        public void run() {
            Message m = handler.obtainMessage();
            try {
                m.obj = getFreeRoom(f, start, end);
                m.what = MessageStatus.SUCCESS.ordinal();
            } catch (Exception e) {
                m.what = MessageStatus.FAILURE.ordinal();
                Bundle b = new Bundle();
                b.putString("message", e.getMessage());
                m.setData(b);
            } finally {
                handler.sendMessage(m);
            }
        }
    }.start();
}

From source file:com.facebook.android.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  . java2s  .c o m*/
 * @throws MalformedURLException - if the URL format is invalid
 * @throws IOException - if a network problem occurs
 */
@Deprecated
public static String openUrl(String url, String method, Bundle params) throws 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);
    }
    Utility.logd("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()) {
            Object parameter = params.get(key);
            if (parameter instanceof byte[]) {
                dataparams.putByteArray(key, (byte[]) parameter);
            }
        }

        // 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());

        try {
            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();
        } finally {
            os.close();
        }
    }

    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.brodev.socialapp.view.MusicPlaySong.java

/** Called when the activity is first created. */
@Override/*from   w ww . j  a va  2  s  . c o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.music_player);

    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    user = (User) getApplication().getApplicationContext();
    colorView = new ColorView(getApplicationContext());

    Bundle bundle = getIntent().getExtras();

    music = (Music) bundle.get("song");

    if (music.getTitle().equals("")) {
        this.getMusicAdapter();
    }
    initView();
    // get comment fragment
    Bundle comment = new Bundle();
    comment.putString("type", "music_song");
    comment.putInt("itemId", Integer.parseInt(music.getSong_id()));
    comment.putInt("totalComment", Integer.parseInt(music.getTotal_comment()));
    comment.putInt("total_like", Integer.parseInt(music.getTotal_like()));
    comment.putBoolean("no_share", music.isShare());
    comment.putBoolean("is_liked", music.isLiked());
    comment.putBoolean("can_post_comment", music.isCanPostComment());

    CommentFragment commentFragment = new CommentFragment();
    commentFragment.setArguments(comment);
    getSupportFragmentManager().beginTransaction().add(R.id.commentfragment_wrap, commentFragment).commit();

}

From source file:com.shanet.relayremote.Main.java

public void getRelayStates() {
    Toast.makeText(this, R.string.refreshingRelays, Toast.LENGTH_SHORT).show();

    // If no relays exist, call the set relays function directly so
    // the list adapters in the fragments are still created
    if (relays.size() == 0) {
        setRelaysAndGroupsStates(null);/*from  w  ww  .  ja  v  a  2  s  .c om*/
    }

    // For each unique server, start a thread to get the state of the relays on that server
    ArrayList<String> servers = new ArrayList<String>();
    Relay relay;
    for (int i = 0; i < relays.size(); i++) {
        relay = relays.get(i);
        if (!servers.contains(relay.getServer())) {
            Bundle bgInfo = new Bundle();
            bgInfo.putChar("op", Constants.OP_GET);
            bgInfo.putString("server", relay.getServer());
            bgInfo.putInt("port", relay.getPort());

            // Add this server to the server list so we don't check it again
            servers.add(relay.getServer());

            new Background(this, Constants.OP_GET, false).execute(bgInfo);
        }
    }
}

From source file:com.dahl.brendan.wordsearch.model.HighScore.java

public Bundle toBundle() {
    Bundle bundle = new Bundle();
    bundle.putLong(Constants.KEY_HIGH_SCORE_TIME, time);
    bundle.putInt(Constants.KEY_HIGH_SCORE_SIZE, size);
    bundle.putString(Constants.KEY_HIGH_SCORE_THEME, theme);
    bundle.putInt(Constants.KEY_WORD_COUNT, wordCount);
    bundle.putString(Constants.KEY_HIGH_SCORE_NAME, name);
    bundle.putInt(Constants.KEY_GLOBAL_RANK, globalRank);
    bundle.putBoolean(Constants.KEY_GLOBAL_HIGH_SCORE, globalHighScore);
    bundle.putInt(Constants.KEY_RANK, rank);
    bundle.putLong(Constants.KEY_HIGH_SCORE, getScore());
    return bundle;
}

From source file:com.parse.ParseAnalyticsTest.java

private Intent makeIntentWithParseData(String pushHash) throws JSONException {
    Intent intent = new Intent();
    Bundle bundle = new Bundle();
    JSONObject json = new JSONObject();
    json.put("push_hash", pushHash);
    bundle.putString(ParsePushBroadcastReceiver.KEY_PUSH_DATA, json.toString());
    intent.putExtras(bundle);/*  w w  w.  ja  va2  s . c o m*/
    return intent;
}

From source file:RhodesService.java

public static void runApplication(String appName, Object params) {
    try {/*from w ww  .ja va  2  s.  com*/
        Context ctx = RhodesService.getContext();
        PackageManager mgr = ctx.getPackageManager();
        PackageInfo info = mgr.getPackageInfo(appName, PackageManager.GET_ACTIVITIES);
        if (info.activities.length == 0) {
            Logger.E(TAG, "No activities found for application " + appName);
            return;
        }
        ActivityInfo ainfo = info.activities[0];
        String className = ainfo.name;
        if (className.startsWith("."))
            className = ainfo.packageName + className;

        Intent intent = new Intent();
        intent.setClassName(appName, className);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (params != null) {
            Bundle startParams = new Bundle();
            if (params instanceof String) {
                if (((String) params).length() != 0) {
                    String[] paramStrings = ((String) params).split("&");
                    for (int i = 0; i < paramStrings.length; ++i) {
                        String key = paramStrings[i];
                        String value = "";
                        int splitIdx = key.indexOf('=');
                        if (splitIdx != -1) {
                            value = key.substring(splitIdx + 1);
                            key = key.substring(0, splitIdx);
                        }
                        startParams.putString(key, value);
                    }
                }
            } else
                throw new IllegalArgumentException("Unknown type of incoming parameter");

            intent.putExtras(startParams);
        }
        ctx.startActivity(intent);
    } catch (Exception e) {
        Logger.E(TAG, "Can't run application " + appName + ": " + e.getMessage());
    }
}