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:net.carlh.toast.MainActivity.java

private void startClient() {
    if (client != null) {
        return;/*from   ww  w. j a va2 s .c  om*/
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    /* Client: this must update the State when it receives new data from the server.
       We also need to know when the client connects or disconnects.
    */

    try {
        client = new Client();

        client.addHandler(new Handler() {
            public void handleMessage(Message message) {

                Bundle data = message.getData();

                if (data != null && data.getString("json") != null) {
                    /* Some state changed */
                    try {
                        state.setFromJSON(new JSONObject(data.getString("json")));
                    } catch (JSONException e) {
                    }
                } else {

                    /* Connected or disconnected */
                    if (getConnected()) {
                        /* Newly connected: ask the server to tell us the basics
                           and then the full temperature history.  The full history
                           can be moderately slow to parse as it can be a few
                           hundred kilobytes.
                        */
                        try {
                            JSONObject json = new JSONObject();
                            json.put("type", "send_basic");
                            client.send(json);
                            json.put("type", "send_all");
                            client.send(json);
                        } catch (JSONException e) {
                        }
                    }
                }
            }
        });

        client.start(prefs.getString("hostname", "192.168.1.1"),
                Integer.parseInt(prefs.getString("port", "80")));

    } catch (IOException e) {
        Log.e("Toast", "IOException in startClient", e);
    }
}

From source file:net.idlesoft.android.apps.github.activities.NewsFeed.java

@Override
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.news_feed);//from ww w  .  j  a  va  2 s  . c  om

    mPrefs = getSharedPreferences(Hubroid.PREFS_NAME, 0);
    mEditor = mPrefs.edit();
    mUsername = mPrefs.getString("username", "");
    mPassword = mPrefs.getString("password", "");

    mGapi.authenticate(mUsername, mPassword);

    ((ImageButton) findViewById(R.id.btn_search)).setOnClickListener(new OnClickListener() {
        public void onClick(final View v) {
            startActivity(new Intent(NewsFeed.this, Search.class));
        }
    });

    final Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        mTargetUser = bundle.getString("username");
        mPrivate = false;
    } else {
        mTargetUser = mUsername;
        mPrivate = true;
    }

    mListView = (ListView) findViewById(R.id.lv_news_feed);
    mListView.setOnItemClickListener(onActivityItemClick);

    mActivityAdapter = new ActivityFeedAdapter(NewsFeed.this, mListView, mPrivate == false);
    if (mPrivate) {
        ((TextView) findViewById(R.id.tv_page_title)).setText("News Feed");
    } else {
        ((TextView) findViewById(R.id.tv_page_title)).setText(mTargetUser + "'s Activity");
    }

    mLoadActivityTask = (LoadActivityFeedTask) getLastNonConfigurationInstance();
    if (mLoadActivityTask == null) {
        mLoadActivityTask = new LoadActivityFeedTask();
    }
    mLoadActivityTask.activity = this;
    if (mLoadActivityTask.getStatus() == AsyncTask.Status.PENDING) {
        mLoadActivityTask.execute();
    }
}

From source file:cn.newgxu.android.bbs.ui.ForumsTopicsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Bundle args = getArguments();
    new GetFromBBS().execute(Consts.DOMAIN + args.getString(Consts.URL));
}

From source file:com.bellman.bible.android.view.activity.search.Search.java

/**
 * Called when the activity is first created.
 *//*from  ww w . j  a  v a  2  s .  c o  m*/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState, true);
    Log.i(TAG, "Displaying Search view");
    setContentView(R.layout.search);

    if (!searchControl.validateIndex(getDocumentToSearch())) {
        Dialogs.getInstance().showErrorMsg(R.string.error_occurred, new Callback() {
            @Override
            public void okay() {
                finish();
            }
        });
    }

    mSearchTextInput = (EditText) findViewById(R.id.searchText);
    mSearchTextInput.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "enter" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                // Perform action on key press
                onSearch(null);
                return true;
            }
            return false;
        }
    });

    // pre-load search string if passed in
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        String searchText = extras.getString(SEARCH_TEXT_SAVE);
        if (StringUtils.isNotEmpty(searchText)) {
            mSearchTextInput.setText(searchText);
        }
    }

    RadioGroup wordsRadioGroup = (RadioGroup) findViewById(R.id.wordsGroup);
    wordsRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            wordsRadioSelection = checkedId;
        }
    });
    if (extras != null) {
        int wordsSelection = extras.getInt(WORDS_SELECTION_SAVE, -1);
        if (wordsSelection != -1) {
            wordsRadioGroup.check(wordsSelection);
        }
    }

    RadioGroup sectionRadioGroup = (RadioGroup) findViewById(R.id.bibleSectionGroup);
    sectionRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            sectionRadioSelection = checkedId;
        }
    });
    if (extras != null) {
        int sectionSelection = extras.getInt(SECTION_SELECTION_SAVE, -1);
        if (sectionSelection != -1) {
            sectionRadioGroup.check(sectionSelection);
        }
    }

    // set text for current bible book on appropriate radio button
    RadioButton currentBookRadioButton = (RadioButton) findViewById(R.id.searchCurrentBook);

    // set current book to default and allow override if saved - implies returning via Back button
    currentBookName = searchControl.getCurrentBookName();
    if (extras != null) {
        String currentBibleBookSaved = extras.getString(CURRENT_BIBLE_BOOK_SAVE);
        if (currentBibleBookSaved != null) {
            currentBookName = currentBibleBookSaved;
        }
    }
    currentBookRadioButton.setText(currentBookName);

    Log.d(TAG, "Finished displaying Search view");
}

From source file:com.qurater.pivotal.gcm.GcmIntentServiceV2.java

@SuppressWarnings("unused")
private void sendNotification(Bundle extras) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    String msg = "";
    String title = "";
    String type = extras.getString("type");
    String id = extras.getString("id");

    String notificationType = "QUESTION";
    int notificationId = Integer.valueOf(id);
    if ("0".equals(type)) {
        String question = extras.getString("question");
        question = (question == null) ? "" : question;
        question = StringEscapeUtils.unescapeHtml(question);
        String from = extras.getString("who");
        msg = question;/*ww w.  j  a v a2s  .c  om*/
        title = from + " needs your help.";
        notificationType = "QUESTION";
    }
    if ("1".equals(type)) {
        String answer = extras.getString("answer");
        answer = (answer == null) ? "" : answer;
        answer = StringEscapeUtils.unescapeHtml(answer);
        String from = extras.getString("who");
        msg = answer;
        title = from + "'s new answer to your request.";
        notificationType = "ANSWER";
    }
    if ("2".equals(type)) {
        String answer = extras.getString("answer");
        answer = (answer == null) ? "" : answer;
        answer = StringEscapeUtils.unescapeHtml(answer);
        String from = extras.getString("who");
        msg = answer;
        title = from + " answered a question you follow.";
        notificationType = "FOLLOW_QUESTION";
    }
    if ("3".equals(type)) {
        String question = extras.getString("question");
        question = (question == null) ? "" : question;
        question = StringEscapeUtils.unescapeHtml(question);
        String from = extras.getString("who");
        msg = question;
        title = from + " refered a question.";
        notificationType = "SHARE";
        notificationId = NOTIFICATION_SHARE_ID;
    }
    try {

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

From source file:com.google.android.apps.authenticator.dataimport.Importer.java

private void importAccountDbFromBundle(Bundle bundle, AccountDb accountDb) {
    // Each account is stored in a Bundle whose key is a string representing the ordinal (integer)
    // position of the account in the database.
    List<String> sortedAccountBundleKeys = new ArrayList<String>(bundle.keySet());
    Collections.sort(sortedAccountBundleKeys, new IntegerStringComparator());
    int importedAccountCount = 0;
    for (String accountBundleKey : sortedAccountBundleKeys) {
        Bundle accountBundle = bundle.getBundle(accountBundleKey);
        String name = accountBundle.getString(KEY_NAME);
        if (name == null) {
            Log.w(LOG_TAG, "Skipping account #" + accountBundleKey + ": name missing");
            continue;
        }/* w w  w .  ja v a  2  s .  co  m*/
        if (accountDb.nameExists(name)) {
            // Don't log account name here and below because it's considered PII
            Log.w(LOG_TAG, "Skipping account #" + accountBundleKey + ": already configured");
            continue;
        }
        String encodedSecret = accountBundle.getString(KEY_ENCODED_SECRET);
        if (encodedSecret == null) {
            Log.w(LOG_TAG, "Skipping account #" + accountBundleKey + ": secret missing");
            continue;
        }
        String typeString = accountBundle.getString(KEY_TYPE);
        AccountDb.OtpType type;
        if ("totp".equals(typeString)) {
            type = AccountDb.OtpType.TOTP;
        } else if ("hotp".equals(typeString)) {
            type = AccountDb.OtpType.HOTP;
        } else {
            Log.w(LOG_TAG,
                    "Skipping account #" + accountBundleKey + ": unsupported type: \"" + typeString + "\"");
            continue;
        }

        Integer counter = accountBundle.containsKey(KEY_COUNTER) ? accountBundle.getInt(KEY_COUNTER) : null;
        if (counter == null) {
            if (type == AccountDb.OtpType.HOTP) {
                Log.w(LOG_TAG, "Skipping account #" + accountBundleKey + ": counter missing");
                continue;
            } else {
                // TOTP
                counter = AccountDb.DEFAULT_HOTP_COUNTER;
            }
        }

        accountDb.update(name, encodedSecret, name, type, counter);
        importedAccountCount++;
    }

    Log.i(LOG_TAG, "Imported " + importedAccountCount + " accounts");
}

From source file:net.healeys.lexic.online.OnlineGame.java

public OnlineGame(Context c, Bundle bun) throws Exception {
    super(c, bun, true);

    uri = bun.getString("uri");

    // Set up userAgent
    PackageManager pm = c.getPackageManager();
    PackageInfo pi = pm.getPackageInfo(c.getPackageName(), 0);
    userAgent = "Lexic (" + pi.packageName + " " + pi.versionName + " " + pi.versionCode + ")";

    // Set up session id
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
    String loginId = prefs.getString("login_id", null);
    sessionid = "sessionid=" + loginId;

    urls = new HashMap<String, String>();
    urls.put("words", bun.getString("words_url"));
    urls.put("score", bun.getString("score_url"));

}

From source file:com.magnet.mmx.client.MMXWakeupIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    //verify the message is a wakeup message
    String action = intent.getAction();
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "onHandleIntent(): action=" + action);
    }/*from w  w  w  . j av a  2 s  .  c om*/
    if ("com.google.android.c2dm.intent.RECEIVE".equals(action)) {
        GooglePlayServicesWrapper playServicesWrapper = GooglePlayServicesWrapper.getInstance(this);
        int messageType = playServicesWrapper.getGcmMessageType(intent);
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "onHandleIntent(): Received message type: " + messageType);
        }
        switch (messageType) {
        case GooglePlayServicesWrapper.GCM_MESSAGE_TYPE_SEND_ERROR:
        case GooglePlayServicesWrapper.GCM_MESSAGE_TYPE_DELETED:
        case GooglePlayServicesWrapper.GCM_MESSAGE_TYPE_SEND_EVENT:
            Log.w(TAG, "onHandleIntent(): Message type is not handled: " + messageType);
            break;
        case GooglePlayServicesWrapper.GCM_MESSAGE_TYPE_MESSAGE:
            //parse the GCM message
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "onHandleIntent(): Handling GCM message.  extras: " + intent.getExtras());
            }
            Bundle extras = intent.getExtras();
            String msg = extras.getString("msg");

            boolean isMmxHandle = false;
            if (msg != null) {
                try {
                    PushMessage pushMessage = PushMessage.decode(msg, MMXTypeMapper.getInstance());
                    isMmxHandle = handleMMXInternalPush(pushMessage);
                    Log.d(TAG, "isMmxHandle=" + isMmxHandle + ", pushMsg=" + pushMessage);
                } catch (UnknownTypeException ex) {
                    //This is not an internal MMX message type
                    Log.i(TAG, "onHandleIntent() forwarding intent to application");
                } catch (Throwable e) {
                    Log.e(TAG, "onHandleIntent() generic exception caught while parsing GCM payload.", e);
                }
            }
            if (!isMmxHandle) {
                MMXClient.handleWakeup(this, intent);
            }
            break;
        }
        MMXGcmBroadcastReceiver.completeWakefulIntent(intent);
    } else {
        if (Intent.ACTION_BOOT_COMPLETED.equals(action) || MMXClient.ACTION_WAKEUP.equals(action)) {
            MMXClient.handleWakeup(this, intent);
        } else {
            //log and do nothing
            Log.w(TAG, "onHandleIntent(): Unsupported action: " + action);
        }
        MMXWakeupReceiver.completeWakefulIntent(intent);
    }
}

From source file:com.dev.pygmy.game.GameHomePageActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gamehomepage);

    getActionBar().setDisplayHomeAsUpEnabled(true);
    button = (Button) findViewById(R.id.play_downloadButton);
    mGame = new GameHolder();

    // Retrieve informations of the game selected
    Bundle extras = getIntent().getExtras();
    mGame.id = extras.getInt("id");
    mGame.name = extras.getString("gameName");
    mGame.summary = extras.getString("summary");
    mGame.filename = extras.getString("filename");
    mGame.version = extras.getString("version");
    mGame.image = extras.getString("image");
    mGame.minPlayers = extras.getInt("minPlayer");
    mGame.maxPlayers = extras.getInt("maxPlayer");

    new FetchUpdateTask().execute();
}

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

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mailaction);

    final boolean replyMode;
    final String messageId;
    final String from;
    final String senderId;
    final String subject;
    final String message;
    Bundle extras = getIntent().getExtras();

    if (extras != null) {
        replyMode = extras.getBoolean("ISREPLY");
        if (replyMode) {
            messageId = extras.getString("MESSAGEID");
            from = extras.getString("SENDER");
            senderId = extras.getString("SENDERID");
            subject = extras.getString("SUBJECT");
            message = extras.getString("MESSAGE");
            extras.putString("CURRENT_USER_ID", null);

            EditText fromText = (EditText) findViewById(R.id.mail_action_to);
            fromText.setEnabled(false);/* w w  w  .j a v a2s.  c o m*/
            EditText subjectText = (EditText) findViewById(R.id.mail_action_subject);
            EditText messageText = (EditText) findViewById(R.id.mail_action_message);

            fromText.setText(from);
            subjectText.setText(subject);
            messageText.setText("\n\n......................................................\n" + message);
        } else {
            messageId = null;
            from = null;
            senderId = null;
            subject = null;
            message = null;
        }
    } else {
        replyMode = false;
        messageId = null;
        from = null;
        senderId = null;
        subject = null;
        message = null;
    }

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

            EditText fromText = (EditText) findViewById(R.id.mail_action_to);
            EditText subjectText = (EditText) findViewById(R.id.mail_action_subject);
            EditText messageText = (EditText) findViewById(R.id.mail_action_message);

            // Prepare the 'send' action
            List<NameValuePair> parameters = new ArrayList<NameValuePair>();
            if (replyMode) {
                parameters.add(new BasicNameValuePair("UserID", senderId));
                parameters.add(new BasicNameValuePair("MessID", messageId));
                parameters.add(new BasicNameValuePair("Referrer",
                        "http://ratebeer.com/showmessage/" + messageId + "/"));
                parameters.add(new BasicNameValuePair("text2", from));
                parameters.add(new BasicNameValuePair("Subject", subject));
                parameters.add(new BasicNameValuePair("Body", messageText.getText().toString()));
                parameters.add(new BasicNameValuePair("nAllowEmail", "0"));
                parameters.add(new BasicNameValuePair("nCc", "0"));
                parameters.add(new BasicNameValuePair("nCcEmail", "android@moerks.dk"));
                parameters.add(new BasicNameValuePair("nCcEmail2", "android@moerks.dk"));
            } else {
                Log.d(LOGTAG, "USERID: " + getUserId());
                parameters.add(new BasicNameValuePair("nSource", getUserId())); //MY User Id
                parameters.add(new BasicNameValuePair("Referrer", "http://ratebeer.com/inbox"));
                parameters.add(new BasicNameValuePair("UserID", "0"));
                parameters.add(new BasicNameValuePair("RecipientName", fromText.getText().toString()));
                parameters.add(new BasicNameValuePair("Subject", subjectText.getText().toString()));
                parameters.add(new BasicNameValuePair("Body", messageText.getText().toString()));
                parameters.add(new BasicNameValuePair("nAllowEmail", "1"));
                parameters.add(new BasicNameValuePair("nCc", "0"));
                parameters.add(new BasicNameValuePair("nCcEmail", "android@moerks.dk"));
                parameters.add(new BasicNameValuePair("nCcEmail2", "android@moerks.dk"));
            }

            new SendBeermailTask(MailAction.this, replyMode)
                    .execute(parameters.toArray(new NameValuePair[] {}));
        }
    });
}