Example usage for android.os Bundle Bundle

List of usage examples for android.os Bundle Bundle

Introduction

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

Prototype

public Bundle() 

Source Link

Document

Constructs a new, empty Bundle.

Usage

From source file:com.comu.android.StreamJsHandler.java

public void postComment(final String post_id, final String message) {
    Bundle params = new Bundle();
    params.putString("message", message);

    getFb().request(post_id + "/comments", params, "POST", new AsyncRequestListener() {

        public void onComplete(JSONObject response, final Object state) {

            try {
                String html = renderComment(response, message);
                html = html.replace("'", "\\'");
                callJs("onComment('" + post_id + "','" + html + "');");
            } catch (JSONException e) {
                e.printStackTrace();//  w  w  w . j av a  2s  .com
            }

        }
    }, null);
}

From source file:com.frublin.androidoauth2.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/*w  w w.  j a va 2 s  . co m*/
 * @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;

    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") + " FoursquareAndroidSDK");
    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("oauth_token")) {
            String decoded_token = URLDecoder.decode(params.getString("oauth_token"));
            params.putString("oauth_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.aikidonord.fragments.FragmentDate.java

@Override
/**//from w w  w .j  av a2s .  c om
 * Au clic sur un lment de la liste.
 */
public void onListItemClick(ListView l, View v, int position, long id) {

    String date = (String) l.getItemAtPosition(position);

    FragmentManager fm = getFragmentManager();

    if (fm.findFragmentById(R.id.fragment_prochains_stages) != null) {

        // affichage tablette
        mCallback.onDateSelected(date);

    } else {

        // dans le cas de l'affichage tlphone classique

        Intent i = new Intent(this.getActivity(), com.aikidonord.ProchainsStages.class);
        // donnes  envoyer  l'activit
        Bundle b = new Bundle();
        b.putString("type", "date");
        b.putString("data", String.valueOf(date));
        i.putExtras(b);
        this.getActivity().startActivity(i);

    }

}

From source file:com.aikidonord.fragments.FragmentLieu.java

@Override
/**/*from   ww  w  .j av a  2 s  .c  o  m*/
 * Au clic sur un lment de la liste.
 */
public void onListItemClick(ListView l, View v, int position, long id) {

    String lieu = (String) l.getItemAtPosition(position);

    FragmentManager fm = getFragmentManager();

    if (fm.findFragmentById(R.id.fragment_prochains_stages) != null) {

        // affichage tablette
        mCallback.onLieuSelected(lieu);

    } else {

        // dans le cas de l'affichage tlphone classique

        Intent i = new Intent(this.getActivity(), com.aikidonord.ProchainsStages.class);
        // donnes  envoyer  l'activit
        Bundle b = new Bundle();
        b.putString("type", "lieu");
        b.putString("data", String.valueOf(lieu));
        i.putExtras(b);
        this.getActivity().startActivity(i);

    }

}

From source file:com.aikidonord.fragments.FragmentType.java

@Override
/**/*from   ww w.  j  a v a  2  s  . c  o m*/
 * Au clic sur un lment de la liste.
 */
public void onListItemClick(ListView l, View v, int position, long id) {

    String type = (String) l.getItemAtPosition(position);

    FragmentManager fm = getFragmentManager();

    if (fm.findFragmentById(R.id.fragment_prochains_stages) != null) {

        // affichage tablette
        mCallback.onTypeSelected(type);

    } else {

        // dans le cas de l'affichage tlphone classique

        Intent i = new Intent(this.getActivity(), com.aikidonord.ProchainsStages.class);
        // donnes  envoyer  l'activit
        Bundle b = new Bundle();
        b.putString("type", "type");
        b.putString("data", String.valueOf(type));
        i.putExtras(b);
        this.getActivity().startActivity(i);

    }

}

From source file:com.google.plus.wigwamnow.social.FacebookProvider.java

/**
 * Share a {@link Wigwam} on the user's timeline using the Feed Dialog.
 *//* w  w w. j  a v  a  2  s .  com*/
@Override
public boolean share(Wigwam wigwam, Activity activity) {
    final Activity hostActivity = activity;

    Session session = Session.getActiveSession();
    if (!hasPublishPermissions()) {
        requestPublishPermissions(session, activity);
        return false;
    }

    final Wigwam toShare = wigwam;
    Bundle postParams = new Bundle();
    postParams.putString("name", wigwam.getName());
    postParams.putString("caption", wigwam.getDescription());
    String host = activity.getResources().getString(R.string.external_host);
    postParams.putString("link", host + "/wigwams/" + Integer.toString(wigwam.getId()));
    postParams.putString("message", "Check out this wigwam!");
    postParams.putString("picture", wigwam.getSrc());

    WebDialog feedDialog = new WebDialog.FeedDialogBuilder(hostActivity, session, postParams)
            .setOnCompleteListener(new OnCompleteListener() {
                @Override
                public void onComplete(Bundle values, FacebookException error) {
                    if (error == null) {
                        final String postId = values.getString("post_id");
                        if (postId != null) {
                            Toast.makeText(hostActivity, "Published to timeline", Toast.LENGTH_SHORT).show();
                        }
                    }
                }
            }).build();
    feedDialog.show();

    return true;
}

From source file:com.nextgis.metroaccess.MetaDownloader.java

@Override
protected Void doInBackground(String... urls) {
    if (IsNetworkAvailible(moContext)) {
        try {// w w w . j  a v  a 2 s. c om
            String sURL = urls[0];

            moHTTPGet = new HttpGet(sURL);

            Log.d(TAG, "HTTPGet URL " + sURL);

            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(moHTTPGet);
            if (response == null)
                return null;
            HttpEntity entity = response.getEntity();

            if (moEventReceiver != null) {
                if (entity != null) {
                    Bundle bundle = new Bundle();
                    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                        bundle.putBoolean(BUNDLE_ERRORMARK_KEY, false);
                        msContent = EntityUtils.toString(entity, HTTP.UTF_8);
                        bundle.putString(BUNDLE_PAYLOAD_KEY, msContent);
                        bundle.putInt(BUNDLE_EVENTSRC_KEY, 1);
                    } else {
                        bundle.putBoolean(BUNDLE_ERRORMARK_KEY, true);
                        bundle.putString(BUNDLE_MSG_KEY, moContext.getString(R.string.sNetworkGetErr));
                        bundle.putInt(BUNDLE_EVENTSRC_KEY, 1);
                    }

                    Message oMsg = new Message();
                    oMsg.setData(bundle);

                    moEventReceiver.sendMessage(oMsg);
                } else {
                    msError = moContext.getString(R.string.sNetworkUnreachErr);
                }
            }

        } catch (ClientProtocolException e) {
            msError = e.getMessage();
            //cancel(true);
        } catch (IOException e) {
            msError = e.getMessage();
            //cancel(true);
        }
    } else {
        if (moEventReceiver != null) {
            Bundle bundle = new Bundle();
            bundle.putBoolean(BUNDLE_ERRORMARK_KEY, true);
            bundle.putString(BUNDLE_MSG_KEY, moContext.getString(R.string.sNetworkUnreachErr));
            bundle.putInt(BUNDLE_EVENTSRC_KEY, 1);

            Message oMsg = new Message();
            oMsg.setData(bundle);
            moEventReceiver.sendMessage(oMsg);
        }
    }
    return null;
}

From source file:com.facebook.samples.socialcafe.MenuFragmentActivity.java

public void requestUserData() {
    Bundle params = new Bundle();
    int screenLayoutSize = getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK;
    if (screenLayoutSize == Configuration.SCREENLAYOUT_SIZE_LARGE
            || screenLayoutSize == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
        params.putString("fields", "name, picture.type(large)");
    } else {// w  ww. j a v a2s  .c  o  m
        params.putString("fields", "name, picture.type(normal)");
    }
    params.putString("fields", "name, picture.type(large)");
    ((SocialCafeApplication) getActivity().getApplication()).asyncRunner.request("me", params,
            new UserDataRequestListener());
}

From source file:com.johan.vertretungsplan.VertretungFragment.java

public static Bundle createBundle(String title) {
    Bundle bundle = new Bundle();
    bundle.putString(EXTRA_TITLE, title);
    return bundle;
}

From source file:com.arthackday.killerapp.GCMIntentService.java

@Override
protected void onMessage(Context ctxt, Intent message) {
    Log.i("REMOVE BEFORE COMMIT", "blahhhhhhh GCMessage");
    Bundle extras = message.getExtras();

    /*/*from w w  w . j a  v  a 2  s. c  o m*/
     * TO DO! CHANGE WHAT THE MESSAGES DO!!
     */

    for (String key : extras.keySet()) {
        Log.i(getClass().getSimpleName(), String.format("onMessage: %s=%s", key, extras.getString(key)));

        if (key.equals(KillerConstants.EXTRA_KEY_AUDIO)) {
            Log.i("REMOVE BEFORE COMMIT", "blahhhhhhh pushAudio");
            Intent i = new Intent();
            Log.i("REMOVE BEFORE COMMIT", extras.getString(key));

            Bundle bundle = new Bundle();
            //Add your data to bundle
            bundle.putString(KillerConstants.EXTRA_KEY_AUDIO, extras.getString(key));
            //Add the bundle to the intent
            i.putExtras(bundle);
            i.setClassName("com.arthackday.killerapp", "com.arthackday.killerapp.PushAudio");
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(i);
        }

        if (key.equals(KillerConstants.EXTRA_KEY_PUSHCALL)) {
            Log.i("REMOVE BEFORE COMMIT", "blahhhhhhh callnumber");
            String number = extras.getString(KillerConstants.EXTRA_KEY_PUSHCALL);
            String uri = "tel:" + number.trim();
            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse(uri));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
    }
}