Example usage for android.os Bundle getString

List of usage examples for android.os Bundle getString

Introduction

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

Prototype

@Nullable
public String getString(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:br.ajmarques.cordova.plugin.localnotification.Receiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Options options = null;//from   w w w  . j av  a  2s  . c  o  m
    Bundle bundle = intent.getExtras();
    JSONObject args;

    try {
        args = new JSONObject(bundle.getString(OPTIONS));
        options = new Options(context).parse(args);
    } catch (JSONException e) {
        return;
    }

    this.context = context;
    this.options = options;

    // The context may got lost if the app was not running before
    LocalNotification.setContext(context);

    if (options.getInterval() == 0) {
        LocalNotification.unpersist(options.getId());
    } else if (isFirstAlarmInFuture()) {
        return;
    } else {
        LocalNotification.add(options.moveDate());
    }

    NotificationCompat.Builder notification = buildNotification();

    if (!isInBackground(context)) {
        invokeForegroundCallback();
    }

    showNotification(notification);
}

From source file:com.chess.genesis.dialog.GameStatsDialog.java

public GameStatsDialog(final Context context, final Bundle bundle) {
    super(context, BaseDialog.CANCEL);

    final int from, to;
    final int status = Integer.parseInt(bundle.getString("status"));
    final int eventtype = Integer.parseInt(bundle.getString("eventtype"));
    final int ycol = bundle.getInt("yourcolor");

    final String[] statusArr = STATUS_MAP.get(status * ycol);
    String gametype = Enums.GameType(Integer.parseInt(bundle.getString("gametype")));
    gametype = gametype.substring(0, 1).toUpperCase(Locale.US) + gametype.substring(1);

    if (ycol == Piece.WHITE) {
        opponent = bundle.getString("black");
        from = Integer.parseInt(bundle.getString("w_psrfrom"));
        to = Integer.parseInt(bundle.getString("w_psrto"));
    } else {//from w w  w.  j  a  v a2  s . c  o m
        opponent = bundle.getString("white");
        from = Integer.parseInt(bundle.getString("b_psrfrom"));
        to = Integer.parseInt(bundle.getString("b_psrto"));
    }

    diff = to - from;
    final String sign = (diff >= 0) ? "+" : "-";

    title = statusArr[0];
    result = statusArr[1];
    psr_type = gametype + " PSR :";

    if (eventtype == Enums.INVITE)
        psr_score = "None (Invite Game)";
    else
        psr_score = sign + String.valueOf(Math.abs(diff)) + " (" + String.valueOf(to) + ')';
}

From source file:org.ohmage.auth.AuthenticatorTest.java

private void verifyTokenInBundle(Bundle bundle) {
    assertEquals(accessToken, bundle.getString(AccountManager.KEY_AUTHTOKEN));
}

From source file:edu.cmu.sei.cloudlet.client.ska.adb.OutDataService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.v(TAG, "Received data request.");
    Bundle extras = intent.getExtras();
    Log.v(TAG, "Number of items requested: " + extras.size());

    JSONObject jsonData = new JSONObject();
    for (String key : extras.keySet()) {
        try {//from   ww  w.  j ava  2  s  .  co m
            jsonData.put(key, extras.getString(key));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    String jsonDataAsString = mDataHandler.getData(jsonData, this);

    Log.v(TAG, "Writing to file.");
    FileHandler.writeToFile(ADBConstants.OUT_FILE_PATH, jsonDataAsString);
    Log.v(TAG, "Finished writing to file.");

    // We don't need this service to run anymore.
    stopSelf();
    return START_NOT_STICKY;
}

From source file:dk.moerks.ratebeermobile.Rate.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.rate);/*from  ww  w  . ja va  2s.c o m*/

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        beername = extras.getString("BEERNAME");
        beerid = extras.getString("BEERID");
    }

    rateCharleftText = (TextView) findViewById(R.id.rate_label_charleft);
    rateCharleftText.setText(getText(R.string.rate_charleft) + " 75");
    EditText rateComment = (EditText) findViewById(R.id.rate_value_comments);
    rateComment.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            int charNumber = s.length();
            int resultNumber = 75 - charNumber;
            if (resultNumber > 0) {
                rateCharleftText.setText(getText(R.string.rate_charleft) + " " + resultNumber);
            } else {
                rateCharleftText.setText("");
            }
        }
    });

    TextView beernameText = (TextView) findViewById(R.id.rate_label_beername);
    beernameText.setText(beername);

    Button rateButton = (Button) findViewById(R.id.rate_button);
    rateButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            EditText comment = (EditText) findViewById(R.id.rate_value_comments);
            final String commentString = comment.getText().toString();

            if (commentString.length() > 74) {

                Spinner aromaText = (Spinner) findViewById(R.id.rate_value_aroma);
                Spinner appearanceText = (Spinner) findViewById(R.id.rate_value_appearance);
                Spinner flavorText = (Spinner) findViewById(R.id.rate_value_flavor);
                Spinner palateText = (Spinner) findViewById(R.id.rate_value_palate);
                Spinner overallText = (Spinner) findViewById(R.id.rate_value_overall);

                final String aromaString = (String) aromaText.getSelectedItem();
                final String appearanceString = (String) appearanceText.getSelectedItem();
                final String flavorString = (String) flavorText.getSelectedItem();
                final String palateString = (String) palateText.getSelectedItem();
                final String overallString = (String) overallText.getSelectedItem();
                String totalScore = calculateTotalScore(aromaString, appearanceString, flavorString,
                        palateString, overallString);

                List<NameValuePair> parameters = new ArrayList<NameValuePair>();
                parameters.add(new BasicNameValuePair("BeerID", beerid));
                parameters.add(new BasicNameValuePair("aroma", aromaString));
                parameters.add(new BasicNameValuePair("appearance", appearanceString));
                parameters.add(new BasicNameValuePair("flavor", flavorString));
                parameters.add(new BasicNameValuePair("palate", palateString));
                parameters.add(new BasicNameValuePair("overall", overallString));
                parameters.add(new BasicNameValuePair("totalscore", totalScore));
                parameters.add(new BasicNameValuePair("Comments", commentString));

                new SaveRatingTask(Rate.this).execute(parameters.toArray(new NameValuePair[] {}));

                SharedPreferences prefs = getSharedPreferences(Settings.PREFERENCETAG, 0);
                if (prefs.getBoolean("rb_twitter_ratings", false)) {
                    new PostTwitterStatusTask(Rate.this).execute(buildTwitterMessage(totalScore));
                }

                finish();

            } else {
                Toast.makeText(Rate.this, R.string.toast_minimum_length, Toast.LENGTH_LONG).show();
            }
        }

        private String buildTwitterMessage(String score) {
            return getString(R.string.twitter_rating_message, beername, score, getUserId());
        }

        private String calculateTotalScore(String aromaString, String appearanceString, String flavorString,
                String palateString, String overallString) {
            int aroma = Integer.parseInt(aromaString);
            int appearance = Integer.parseInt(appearanceString);
            int flavor = Integer.parseInt(flavorString);
            int palate = Integer.parseInt(palateString);
            int overall = Integer.parseInt(overallString);

            int total = (aroma + appearance + flavor + palate + overall);

            float totalscore = ((float) total) / 10;
            String result = "" + totalscore;
            return result;
        }
    });
}

From source file:com.amazon.cordova.plugin.ADMMessageHandler.java

/** {@inheritDoc} */
@Override/*ww w  .  j a  v  a2  s. co  m*/
protected void onMessage(final Intent intent) {
    // Extract the message content from the set of extras attached to
    // the com.amazon.device.messaging.intent.RECEIVE intent.

    // Extract the payload from the message
    Bundle extras = intent.getExtras();
    if (extras != null && (extras.getString(PushPlugin.MESSAGE) != null)) {
        // if we are in the foreground, just surface the payload, else post
        // it to the statusbar
        if (PushPlugin.isInForeground()) {
            extras.putBoolean(PushPlugin.FOREGROUND, true);
            PushPlugin.sendExtras(extras);
        } else {
            extras.putBoolean(PushPlugin.FOREGROUND, false);
            createNotification(this, extras);
        }
    }
}

From source file:com.rincliu.library.common.reference.social.weibo.RLWeiboHelper.java

/**
 * @param activity//from  w w w .j  a  va2  s  .  com
 * @param handler
 * @return
 */
public SsoHandler auth(final Activity activity, final ReqHandler handler) {
    SsoHandler ssoHandler = new SsoHandler(activity, weibo);
    ssoHandler.authorize(new WeiboAuthListener() {
        @Override
        public void onComplete(Bundle data) {
            AccessTokenKeeper.clear(activity);
            Oauth2AccessToken token = new Oauth2AccessToken(data.getString("access_token"),
                    data.getString("expires_in"));
            AccessTokenKeeper.keepAccessToken(activity, token);
            handler.onSucceed();
        }

        @Override
        public void onCancel() {
            handler.onFail(activity.getString(R.string.weibo_auth_cancel));
        }

        @Override
        public void onError(WeiboDialogError error) {
            handler.onFail(error.getMessage());
        }

        @Override
        public void onWeiboException(WeiboException exception) {
            handler.onFail(exception.getMessage());
        }
    });
    return ssoHandler;
}

From source file:com.nagopy.android.xposed.SettingChangedReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Object obj = dataObject.get();
    if (!StringUtils.equals(intent.getAction(), action) || obj == null) {
        context.unregisterReceiver(this);
        return;//from   w  ww  .  ja v  a2  s.  com
    }

    Bundle extras = intent.getExtras();
    if (extras == null || extras.size() != 2) {
        return;
    }

    try {
        // target?value????????
        String target = extras.getString("target");
        Object value = extras.get("value");
        obj.getClass().getField(target).set(obj, value);

        onDataChanged();
    } catch (Throwable t) {
        Logger.e(getClass().getSimpleName(), Log.getStackTraceString(t));
    }
}

From source file:com.groupme.sdk.util.HttpUtilsTest.java

public void testSetHttpParamsGet() {
    MockHttpClient client = new MockHttpClient();
    client.setContext(getContext());//from   w  ww  . j  av a  2  s. c  o m
    String response = null;

    try {
        Bundle params = new Bundle();
        params.putString("group", "mygroup");
        params.putString("format", "json");

        response = HttpUtils.openUrl(client, OK_REQUEST, HttpUtils.METHOD_GET, null, params, null);
    } catch (HttpResponseException e) {
        fail("Received a response exception: " + e.toString());
    }

    String query = client.getRequest().getURI().getQuery();
    Bundle requestParams = HttpUtils.decodeParams(query);

    if (requestParams != null && !requestParams.isEmpty()) {
        assertEquals("mygroup", requestParams.getString("group"));
        assertEquals("json", requestParams.getString("format"));
    } else {
        fail("Params are not set!");
    }

    if (response == null) {
        fail("Unexpected empty response");
    }
}

From source file:com.krayzk9s.imgurholo.ui.AlbumsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle bundle = getArguments();
    username = bundle.getString("username");
    setHasOptionsMenu(true);//ww  w .  j a va 2s.  c om
}