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.parse.ParseAnalyticsTest.java

@Test
public void testGetPushHashFromIntentWrongPushHashIntent() throws Exception {
    Intent intent = new Intent();
    Bundle bundle = new Bundle();
    bundle.putString(ParsePushBroadcastReceiver.KEY_PUSH_DATA, "error_data");
    intent.putExtras(bundle);/*from w  w w .  j a va2 s  .  c  om*/

    String pushHash = ParseAnalytics.getPushHashFromIntent(intent);

    assertEquals(null, pushHash);
}

From source file:com.nextgis.firereporter.HttpGetter.java

@Override
protected void onPostExecute(Void unused) {
    super.onPostExecute(unused);
    DismissDowloadDialog();/*from w w  w .  j av  a2  s.c o  m*/
    if (mError != null) {
        Bundle bundle = new Bundle();
        bundle.putBoolean(GetFiresService.ERROR, true);
        bundle.putString(GetFiresService.ERR_MSG, mError);
        bundle.putInt(GetFiresService.SOURCE, mnType);

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

        if (mEventReceiver != null) {
            mEventReceiver.sendMessage(msg);
        }
    } else {
        //Toast.makeText(MainActivity.this, "Source: " + Content, Toast.LENGTH_LONG).show();
    }
}

From source file:ibp.plugin.nsd.NSDHelper.java

public void sendNotification(String type, String msg) {
    Bundle messageBundle = new Bundle();
    messageBundle.putString("type", type);
    messageBundle.putString("msg", msg);
    Message message = new Message();
    message.setData(messageBundle);/* www.  j av  a  2  s.co  m*/
    mHandler.sendMessage(message);
}

From source file:it.scoppelletti.mobilepower.widget.DateControl.java

protected void onSaveInstanceState(Bundle outState) {
    if (!StringUtils.isBlank(myDialogTag)) {
        outState.putString(DateControl.STATE_DIALOGTAG, myDialogTag);
    }/*from w w  w  .j  a v a2  s  .co  m*/
    if (myIsEmptyAllowed) {
        outState.putBoolean(DateControl.STATE_ISEMPTYALLOWED, true);
    }
    if (myIsResetEnabled) {
        outState.putBoolean(DateControl.STATE_ISRESETENABLED, true);
    }
    if (!ValueTools.isNullOrEmpty(myValue)) {
        outState.putParcelable(DateControl.STATE_VALUE, myValue);
    }
    if (myValueControl.getError() != null) {
        outState.putCharSequence(DateControl.STATE_ERROR, myValueControl.getError());
    }
}

From source file:com.nextgis.firereporter.ScanexHttpLogin.java

@Override
protected void onPostExecute(Void unused) {
    super.onPostExecute(unused);
    if (mbShowProgress) {
        mDownloadDialog.dismiss();//from w ww .  j a v a 2s  . c  o m
    }
    if (mError != null) {
        Bundle bundle = new Bundle();
        bundle.putBoolean(GetFiresService.ERROR, true);
        bundle.putString(GetFiresService.ERR_MSG, mError);
        bundle.putInt(GetFiresService.SOURCE, mnType);

        Message msg = new Message();
        msg.setData(bundle);
        if (mEventReceiver != null) {
            mEventReceiver.sendMessage(msg);
        }
    }
}

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/*from   w  w w .  ja v  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;

    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.goliathonline.android.kegbot.service.SyncService.java

@Override
protected void onHandleIntent(Intent intent) {
    Log.d(TAG, "onHandleIntent(intent=" + intent.toString() + ")");

    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER);
    if (receiver != null)
        receiver.send(STATUS_RUNNING, Bundle.EMPTY);

    final Context context = this;
    final SharedPreferences prefs = getSharedPreferences(Prefs.IOSCHED_SYNC, Context.MODE_PRIVATE);
    final int localVersion = prefs.getInt(Prefs.LOCAL_VERSION, VERSION_NONE);

    try {//  ww  w  . j a v a 2s  . co m
        // Bulk of sync work, performed by executing several fetches from
        // local and online sources.

        final long startLocal = System.currentTimeMillis();
        final boolean localParse = localVersion < VERSION_CURRENT;
        Log.d(TAG, "found localVersion=" + localVersion + " and VERSION_CURRENT=" + VERSION_CURRENT);
        if (localParse) {

            // Parse values from local cache first, since spreadsheet copy
            // or network might be down.
            //mLocalExecutor.execute(context, "cache-drinks.json", new RemoteDrinksHandler());
            //mLocalExecutor.execute(context, "cache-speakers.xml", new RemoteSpeakersHandler());
            //mLocalExecutor.execute(context, "cache-vendors.xml", new RemoteVendorsHandler());

            // Save local parsed version
            prefs.edit().putInt(Prefs.LOCAL_VERSION, VERSION_CURRENT).commit();
        }
        Log.d(TAG, "local sync took " + (System.currentTimeMillis() - startLocal) + "ms");

        // Always hit remote spreadsheet for any updates
        final long startRemote = System.currentTimeMillis();
        mRemoteExecutor.executeGet(PrefsHelper.getAPIUrl(getBaseContext()) + "/events",
                new RemoteJsonHandler(mRemoteExecutor));
        Log.d(TAG, "remote sync took " + (System.currentTimeMillis() - startRemote) + "ms");

    } catch (Exception e) {
        Log.e(TAG, "Problem while syncing", e);

        if (receiver != null) {
            // Pass back error to surface listener
            final Bundle bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, e.toString());
            receiver.send(STATUS_ERROR, bundle);
        }
    }

    // Announce success to any surface listener
    Log.d(TAG, "sync finished");
    if (receiver != null)
        receiver.send(STATUS_FINISHED, Bundle.EMPTY);
}

From source file:com.facebook.AccessTokenTest.java

@Test
public void testCreateFromRefreshFailure() {
    AccessToken accessToken = new AccessToken("a token", "1234", "1000", Utility.arrayList("stream_publish"),
            null, AccessTokenSource.WEB_VIEW, null, null);

    String token = "AnImaginaryTokenValue";

    Bundle bundle = new Bundle();
    bundle.putString("access_token", "AnImaginaryTokenValue");
    bundle.putString("expires_in", "60");

    try {/*w  w  w  . ja  va2 s .  c om*/
        AccessToken.createFromRefresh(accessToken, bundle);
        fail("Expected exception");
    } catch (FacebookException ex) {
        assertEquals("Invalid token source: " + AccessTokenSource.WEB_VIEW, ex.getMessage());
    }
}

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

/**
 * Initiate server-side authorization by sending a one time code to the server.
 *//* www . j ava 2s  .co  m*/
@Override
public void hybridAuth(final Activity activity) {
    // Check that the activity has a PlusClient
    if (!(activity instanceof PlusClientHostActivity)) {
        throw new IllegalArgumentException("Activity must host a PlusClient!");
    }

    final PlusClientHostActivity clientHost = (PlusClientHostActivity) activity;

    // Create the hybrid authorization resources
    final String clientId = activity.getResources().getString(R.string.plus_client_id);
    final String[] activities = activity.getResources().getStringArray(R.array.visible_activities);
    final String[] scopes = activity.getResources().getStringArray(R.array.plus_scopes);
    final String scopeString = "oauth2:server:client_id:" + clientId + ":api_scope:"
            + TextUtils.join(" ", scopes);

    final Bundle appActivities = new Bundle();
    appActivities.putString(GoogleAuthUtil.KEY_REQUEST_VISIBLE_ACTIVITIES, TextUtils.join(" ", activities));

    AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {

        final Activity hostActivity = activity;

        @Override
        protected String doInBackground(Void... params) {
            try {
                return GoogleAuthUtil.getToken(hostActivity, clientHost.getPlusClient().getAccountName(),
                        scopeString, appActivities);
            } catch (IOException transientEx) {
                // Network or server error, try later
                Log.e(TAG, transientEx.toString(), transientEx);
                return null;
            } catch (UserRecoverableAuthException e) {
                // Recover (with e.getIntent())
                Log.e(TAG, e.toString(), e);
                Intent recover = e.getIntent();
                hostActivity.startActivityForResult(recover, REQUEST_CODE_TOKEN_AUTH);
            } catch (GoogleAuthException authEx) {
                // The call is not ever expected to succeed and should not be retried.
                Log.e(TAG, authEx.toString(), authEx);
                return null;
            } catch (Exception e) {
                Log.e(TAG, e.toString(), e);
                throw new RuntimeException(e);
            }

            return null;
        }

        @Override
        protected void onPostExecute(String code) {
            Log.d(TAG, "Authorization code retrieved:" + code);
            if (code != null && !mPendingCodeSend) {
                mPendingCodeSend = true;
                initGoogleHybridFlow(code, hostActivity);
            }
        }

    };
    task.execute();

}

From source file:com.nextgis.maplibui.formcontrol.DoubleCombobox.java

@Override
public void saveState(Bundle outState) {
    DoubleComboboxValue result = (DoubleComboboxValue) getValue();
    outState.putString(ControlHelper.getSavedStateKey(mFieldName), result.mValue);
    outState.putString(ControlHelper.getSavedStateKey(mSubFieldName), result.mSubValue);
}