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:org.umit.icm.mobile.social.TwitterUpdate.java

/**
 * Sends a Tweet using the Notification Service. 
 * /*from   w  w w.  j  a va 2 s  . co m*/
 * 
         
 @param   message      An object of type String which represents the Tweet.
 *
         
 @see Intent 
 */
public synchronized void sendTweet(String message, Context context) {
    Bundle bundle = new Bundle();
    bundle.putString("twitter", message);
    Intent intent = new Intent("org.umit.icm.mobile.TWITTER_SERVICE");
    intent.putExtras(bundle);
    context.sendBroadcast(intent);
}

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  ww w.j  a v a 2 s. c o  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;

    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.katamaditya.apps.weather4u.weathersync.Weather4USyncAdapter.java

/**
 * Helper method to have the sync adapter sync immediately
 *
 * @param context The context used to access the account service
 *///from  w w  w. ja va2 s . com
public static void syncImmediately(Context context) {
    //Log.d("Weather4USyncAdapter", "syncImmediately");
    Bundle bundle = new Bundle();
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    ContentResolver.requestSync(getSyncAccount(context), context.getString(R.string.content_authority), bundle);
}

From source file:com.myinstagram.afinski.myinstgrmviewer.ui.ImageGridFragment.java

private void startLoading(String url) {
    Bundle args = new Bundle();
    args.putString("url", url);
    //        loader = getActivity().getLoaderManager().getLoader(0);
    loader = getLoaderManager().initLoader(0, args, this);
    if (loader != null && !loader.isStarted()) {
        loader.forceLoad();//from   ww w. j  a va 2s .c  o m
    } else {
        //            loader = new PictureLoader(mActivityContext,args);
        loader.forceLoad();
        //            loader =  getLoaderManager().initLoader(0, args, this);
    }
}

From source file:com.skubit.android.example.MainActivity.java

public void fetchSkus(final ListView view) {
    Thread t = new Thread(new Runnable() {

        @Override/* w  ww  .j  ava 2  s .  c  o  m*/
        public void run() {
            ArrayList<String> ids = new ArrayList<String>();
            ///ids.add("445");
            //ids.add("440");
            ids.add("contribA");
            final Bundle skusBundle = new Bundle();
            skusBundle.putStringArrayList("ITEM_ID_LIST", ids);

            try {
                Bundle skuDetails = mService.getSkuDetails(1, getApplicationContext().getPackageName(),
                        "donation", skusBundle);

                final ArrayList<String> details = skuDetails.getStringArrayList("DETAILS_LIST");
                final SkusFragment skusFragment = (SkusFragment) mAdapter.getItem(0);

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            skusFragment.displaySkus(MainActivity.this, view, details);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });

            } catch (Exception e) {
                e.printStackTrace();
            }

        }

    });
    t.start();

}

From source file:com.groupme.sdk.GroupMeConnect.java

public void authorizePhoneNumber(String phoneNumber, GroupMeRequest.RequestListener listener) {
    GroupMeRequest request = new GroupMeRequest();
    request.setRequest(GroupMeRequest.CLIENT_AUTHORIZE, HttpUtils.METHOD_POST);
    request.setRequestListener(listener);

    Bundle params = new Bundle();
    params.putString("client_id", mAppId);
    params.putString("client_secret", mSecret);
    params.putString("device_id", "my-super-cool-device-id");
    params.putString("grant_type", "client_credentials");
    params.putString("phone_number", phoneNumber);

    request.setParams(params);//from  w  w w. jav a 2s .c  o m
    request.start();
}

From source file:at.wada811.android.library.demos.loader.LoaderListFragment.java

/**
 * URL???/*from ww  w .j a v a  2 s.  c  o m*/
 * 
 * @param url ?URL
 */
private void searchImageWithUrl(String url) {
    LogUtils.i(url);
    Loader<Object> currentLoader = getLoaderManager().getLoader(mLoaderListAdapter.getCount());
    if (currentLoader != null && currentLoader.isStarted()) {
        // ?
        LogUtils.i("canceled!");
        return;
    }
    Bundle args = new Bundle();
    args.putInt(LoaderListFragment.KEY_START_INDEX, mLoaderListAdapter.getCount());
    args.putString(LoaderListFragment.KEY_SEARCH_URL, url);
    getLoaderManager().restartLoader(mLoaderListAdapter.getCount(), args, new LoaderCallbacks<Void>() {
        @Override
        public Loader<Void> onCreateLoader(int id, Bundle args) {
            LogUtils.i("LoaderId: " + id);
            return new AsyncImageSearchLoader(getActivity(), args, new JsonHttpResponseHandler() {
                @Override
                public void onSuccess(int statusCode, JSONObject response) {
                    super.onSuccess(statusCode, response);
                    LogUtils.d("statusCode: " + statusCode);
                    try {
                        int responseStatus = response.getInt("responseStatus");
                        LogUtils.d("responseStatus: " + responseStatus);
                        if (responseStatus != 200) {
                            return;
                        }
                        JSONObject responseData = response.getJSONObject("responseData");
                        JSONArray results = responseData.getJSONArray("results");
                        ArrayList<LoaderListItem> resultsList = new ArrayList<LoaderListItem>(results.length());
                        for (int i = 0; i < results.length(); i++) {
                            JSONObject result = results.getJSONObject(i);
                            LoaderListItem item = new LoaderListItem();
                            item.setImageUrl(result.getString("unescapedUrl"));
                            item.setThumbnailUrl(result.getString("tbUrl"));
                            item.setImageTitle(result.getString("titleNoFormatting"));
                            item.setImageWidth(Integer.valueOf(result.getString("width")));
                            item.setImageHeight(Integer.valueOf(result.getString("height")));
                            resultsList.add(item);
                        }
                        if (mLoaderListAdapter.getCount() == 0) {
                            setListShown(true);
                        }
                        if (resultsList.size() > 0) {
                            mLoaderListAdapter.addAll(resultsList);
                            getListView().invalidateViews();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                        LogUtils.e(e);
                    }
                }

                @Override
                public void onFailure(int statusCode, Throwable e, JSONObject errorResponse) {
                    super.onFailure(statusCode, e, errorResponse);
                    LogUtils.e("statusCode: " + statusCode);
                    LogUtils.e(e);
                }
            });
        }

        @Override
        public void onLoadFinished(Loader<Void> loader, Void data) {
            LogUtils.i("LoaderId: " + loader.getId());
        }

        @Override
        public void onLoaderReset(Loader<Void> loader) {
            LogUtils.i();
        }
    });
}

From source file:fr.cph.chicago.fragment.NearbyFragment.java

/**
 * Returns a new instance of this fragment for the given section number.
 * /*from   w w  w  .ja  va 2  s. c o m*/
 * @param sectionNumber
 * @return
 */
public static NearbyFragment newInstance(final int sectionNumber) {
    NearbyFragment fragment = new NearbyFragment();
    Bundle args = new Bundle();
    args.putInt(ARG_SECTION_NUMBER, sectionNumber);
    fragment.setArguments(args);
    return fragment;
}

From source file:com.kinvey.sample.signin.GoogleLoginActivity.java

private void finishLogin(String authToken, String password) {
    final Account account = new Account(authToken, UserLogin.ACCOUNT_TYPE);
    Bundle userData = new Bundle();
    userData.putString(UserLogin.LOGIN_TYPE_KEY, PARAM_LOGIN_TYPE_GOOGLE);
    mAccountManager.addAccountExplicitly(account, password, userData);

    final Intent intent = new Intent();
    intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, authToken);
    intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, UserLogin.ACCOUNT_TYPE);
    setResult(RESULT_OK, intent);//from w ww  . j  a v  a 2  s  .  co m
    finish();
}

From source file:com.ble.facebook.Util.java

/**
 * Connect to an HTTP URL and return the response as a string.
 * //from  ww w.  ja v a  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("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;
}