Example usage for android.content Intent getStringArrayExtra

List of usage examples for android.content Intent getStringArrayExtra

Introduction

In this page you can find the example usage for android.content Intent getStringArrayExtra.

Prototype

public String[] getStringArrayExtra(String name) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.android.mail.compose.ComposeActivity.java

/**
 * Fill all the widgets with the content found in the Intent Extra, if any.
 * Also apply the same style to all widgets. Note: if initFromExtras is
 * called as a result of switching between reply, reply all, and forward per
 * the latest revision of Gmail, and the user has already made changes to
 * attachments on a previous incarnation of the message (as a reply, reply
 * all, or forward), the original attachments from the message will not be
 * re-instantiated. The user's changes will be respected. This follows the
 * web gmail interaction./*  w ww . j a  v a  2s. c  om*/
 * @return {@code true} if the activity should not call {@link #finishSetup}.
 */
public boolean initFromExtras(Intent intent) {
    // If we were invoked with a SENDTO intent, the value
    // should take precedence
    final Uri dataUri = intent.getData();
    if (dataUri != null) {
        if (MAIL_TO.equals(dataUri.getScheme())) {
            initFromMailTo(dataUri.toString());
        } else {
            if (!mAccount.composeIntentUri.equals(dataUri)) {
                String toText = dataUri.getSchemeSpecificPart();
                if (toText != null) {
                    mTo.setText("");
                    addToAddresses(Arrays.asList(TextUtils.split(toText, ",")));
                }
            }
        }
    }

    String[] extraStrings = intent.getStringArrayExtra(Intent.EXTRA_EMAIL);
    if (extraStrings != null) {
        addToAddresses(Arrays.asList(extraStrings));
    }
    extraStrings = intent.getStringArrayExtra(Intent.EXTRA_CC);
    if (extraStrings != null) {
        addCcAddresses(Arrays.asList(extraStrings), null);
    }
    extraStrings = intent.getStringArrayExtra(Intent.EXTRA_BCC);
    if (extraStrings != null) {
        addBccAddresses(Arrays.asList(extraStrings));
    }

    String extraString = intent.getStringExtra(Intent.EXTRA_SUBJECT);
    if (extraString != null) {
        mSubject.setText(extraString);
    }

    for (String extra : ALL_EXTRAS) {
        if (intent.hasExtra(extra)) {
            String value = intent.getStringExtra(extra);
            if (EXTRA_TO.equals(extra)) {
                addToAddresses(Arrays.asList(TextUtils.split(value, ",")));
            } else if (EXTRA_CC.equals(extra)) {
                addCcAddresses(Arrays.asList(TextUtils.split(value, ",")), null);
            } else if (EXTRA_BCC.equals(extra)) {
                addBccAddresses(Arrays.asList(TextUtils.split(value, ",")));
            } else if (EXTRA_SUBJECT.equals(extra)) {
                mSubject.setText(value);
            } else if (EXTRA_BODY.equals(extra)) {
                setBody(value, true /* with signature */);
            } else if (EXTRA_QUOTED_TEXT.equals(extra)) {
                initQuotedText(value, true /* shouldQuoteText */);
            }
        }
    }

    Bundle extras = intent.getExtras();
    if (extras != null) {
        CharSequence text = extras.getCharSequence(Intent.EXTRA_TEXT);
        setBody((text != null) ? text : "", true /* with signature */);

        // TODO - support EXTRA_HTML_TEXT
    }

    mExtraValues = intent.getParcelableExtra(EXTRA_VALUES);
    if (mExtraValues != null) {
        LogUtils.d(LOG_TAG, "Launched with extra values: %s", mExtraValues.toString());
        initExtraValues(mExtraValues);
        return true;
    }

    return false;
}

From source file:com.tct.mail.compose.ComposeActivity.java

/**
 * Fill all the widgets with the content found in the Intent Extra, if any.
 * Also apply the same style to all widgets. Note: if initFromExtras is
 * called as a result of switching between reply, reply all, and forward per
 * the latest revision of Gmail, and the user has already made changes to
 * attachments on a previous incarnation of the message (as a reply, reply
 * all, or forward), the original attachments from the message will not be
 * re-instantiated. The user's changes will be respected. This follows the
 * web gmail interaction.//w  w w. j av  a  2 s  . c o  m
 * @return {@code true} if the activity should not call {@link #finishSetup}.
 */
public boolean initFromExtras(Intent intent) {
    // If we were invoked with a SENDTO intent, the value
    // should take precedence
    final Uri dataUri = intent.getData();
    if (dataUri != null) {
        if (MAIL_TO.equals(dataUri.getScheme())) {
            initFromMailTo(dataUri.toString());
        } else {
            if (!mAccount.composeIntentUri.equals(dataUri)) {
                String toText = dataUri.getSchemeSpecificPart();
                // TS: junwei-xu 2015-03-23 EMAIL BUGFIX_980239 MOD_S
                //if (toText != null) {
                if (Address.isAllValid(toText)) {
                    // TS: junwei-xu 2015-04-23 EMAIL BUGFIX_980239 MOD_E
                    mTo.setText("");
                    addToAddresses(Arrays.asList(TextUtils.split(toText, ",")));
                }
            }
        }
    }

    String[] extraStrings = intent.getStringArrayExtra(Intent.EXTRA_EMAIL);
    if (extraStrings != null) {
        addToAddresses(Arrays.asList(extraStrings));
    }
    extraStrings = intent.getStringArrayExtra(Intent.EXTRA_CC);
    if (extraStrings != null) {
        addCcAddresses(Arrays.asList(extraStrings), null);
    }
    extraStrings = intent.getStringArrayExtra(Intent.EXTRA_BCC);
    if (extraStrings != null) {
        addBccAddresses(Arrays.asList(extraStrings));
    }

    String extraString = intent.getStringExtra(Intent.EXTRA_SUBJECT);
    if (extraString != null) {
        mSubject.setText(extraString);
    }

    for (String extra : ALL_EXTRAS) {
        if (intent.hasExtra(extra)) {
            String value = intent.getStringExtra(extra);
            if (EXTRA_TO.equals(extra)) {
                addToAddresses(Arrays.asList(TextUtils.split(value, ",")));
            } else if (EXTRA_CC.equals(extra)) {
                addCcAddresses(Arrays.asList(TextUtils.split(value, ",")), null);
            } else if (EXTRA_BCC.equals(extra)) {
                addBccAddresses(Arrays.asList(TextUtils.split(value, ",")));
            } else if (EXTRA_SUBJECT.equals(extra)) {
                mSubject.setText(value);
            } else if (EXTRA_BODY.equals(extra)) {
                //[BUGFIX]-Add-BEGINbySCDTABLET.yafang.wei,07/21/2016,2565329
                // Modifytofixsignatureshowsbeforebodyissuewhensharewebsitebyemail
                if (mBodyView.getText().toString().trim()
                        .equals(convertToPrintableSignature(mSignature).trim())) {
                    mBodyView.setText("");
                    setBody(value, true /* with signature */);
                    appendSignature();
                } else {
                    setBody(value, true /* with signature */);
                }
                //[BUGFIX]-Add-ENDbySCDTABLET.yafang.wei
            } else if (EXTRA_QUOTED_TEXT.equals(extra)) {
                initQuotedText(value, true /* shouldQuoteText */);
            }
        }
    }

    Bundle extras = intent.getExtras();
    //[BUGFIX]-MOD-BEGIN by TSNJ,wenlu.wu,10/20/2014,FR-739335
    if (extras != null && !mBodyAlreadySet) {
        //[BUGFIX]-MOD-END by TSNJ,wenlu.wu,10/20/2014,FR-739335
        CharSequence text = extras.getCharSequence(Intent.EXTRA_TEXT);
        //[BUGFIX]-Add-BEGINbySCDTABLET.yafang.wei,07/21/2016,2565329
        // Modifytofixsignatureshowsbeforebodyissuewhensharewebsitebyemail
        if (mBodyView.getText().toString().trim().equals(convertToPrintableSignature(mSignature).trim())) {
            mBodyView.setText("");
            setBody((text != null) ? text : "", true /* with signature */);
            appendSignature();
        } else {
            setBody((text != null) ? text : "", true /* with signature */);
        }
        //[BUGFIX]-Add-ENDbySCDTABLET.yafang.wei

        // TODO - support EXTRA_HTML_TEXT
    }

    mExtraValues = intent.getParcelableExtra(EXTRA_VALUES);
    if (mExtraValues != null) {
        LogUtils.d(LOG_TAG, "Launched with extra values: %s", mExtraValues.toString());
        initExtraValues(mExtraValues);
        return true;
    }

    return false;
}

From source file:com.app.khclub.base.easeim.activity.ChatActivity.java

/**
 * onActivityResult/*from w  ww . java2 s  .  co m*/
 */
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_CODE_EXIT_GROUP) {
        setResult(RESULT_OK);
        finish();
        return;
    }
    if (requestCode == REQUEST_CODE_CONTEXT_MENU) {
        switch (resultCode) {
        case RESULT_CODE_COPY: // ??
            EMMessage copyMsg = ((EMMessage) adapter.getItem(data.getIntExtra("position", -1)));
            // clipboard.setText(SmileUtils.getSmiledText(ChatActivity.this,
            // ((TextMessageBody) copyMsg.getBody()).getMessage()));
            clipboard.setText(((TextMessageBody) copyMsg.getBody()).getMessage());
            break;
        case RESULT_CODE_DELETE: // ?
            EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1));
            conversation.removeMessage(deleteMsg.getMsgId());
            adapter.refreshSeekTo(data.getIntExtra("position", adapter.getCount()) - 1);
            break;

        case RESULT_CODE_FORWARD: // ??
            EMMessage forwardMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", 0));
            Intent intent = new Intent(this, ForwardMessageActivity.class);
            intent.putExtra("forward_msg_id", forwardMsg.getMsgId());
            startActivity(intent);

            break;
        default:
            break;
        }
    }
    if (resultCode == RESULT_OK) { // ?
        LogUtils.i("!!! " + requestCode + " " + resultCode, 1);
        if (requestCode == REQUEST_CODE_EMPTY_HISTORY) {
            // ?
            EMChatManager.getInstance().clearConversation(toChatUsername);
            adapter.refresh();
        } else if (requestCode == REQUEST_CODE_CAMERA) { // ??
            if (cameraFile != null && cameraFile.exists())
                sendPicture(cameraFile.getAbsolutePath());
        } else if (requestCode == REQUEST_CODE_SELECT_VIDEO) { // ??

            int duration = data.getIntExtra("dur", 0);
            String videoPath = data.getStringExtra("path");
            File file = new File(PathUtil.getInstance().getImagePath(), "thvideo" + System.currentTimeMillis());
            Bitmap bitmap = null;
            FileOutputStream fos = null;
            try {
                if (!file.getParentFile().exists()) {
                    file.getParentFile().mkdirs();
                }
                bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, 3);
                if (bitmap == null) {
                    EMLog.d("chatactivity", "problem load video thumbnail bitmap,use default icon");
                    bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.app_panel_video_icon);
                }
                fos = new FileOutputStream(file);

                bitmap.compress(CompressFormat.JPEG, 100, fos);

            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (fos != null) {
                    try {
                        fos.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    fos = null;
                }
                if (bitmap != null) {
                    bitmap.recycle();
                    bitmap = null;
                }

            }
            sendVideo(videoPath, file.getAbsolutePath(), duration / 1000);

        } else if (requestCode == REQUEST_CODE_LOCAL) { // ??
            if (data != null) {
                Uri selectedImage = data.getData();
                if (selectedImage != null) {
                    sendPicByUri(selectedImage);
                }
            }
        } else if (requestCode == REQUEST_CODE_SELECT_FILE) { // ??
            if (data != null) {
                Uri uri = data.getData();
                if (uri != null) {
                    sendFile(uri);
                }
            }

        } else if (requestCode == REQUEST_CODE_MAP) { // 
            double latitude = data.getDoubleExtra("latitude", 0);
            double longitude = data.getDoubleExtra("longitude", 0);
            String locationAddress = data.getStringExtra("address");
            if (locationAddress != null && !locationAddress.equals("")) {
                toggleMore(more);
                sendLocationMsg(latitude, longitude, "", locationAddress);
            } else {
                String st = getResources().getString(R.string.unable_to_get_loaction);
                Toast.makeText(this, st, 0).show();
            }
            // ???
        } else if (requestCode == REQUEST_CODE_TEXT || requestCode == REQUEST_CODE_VOICE
                || requestCode == REQUEST_CODE_PICTURE || requestCode == REQUEST_CODE_LOCATION
                || requestCode == REQUEST_CODE_VIDEO || requestCode == REQUEST_CODE_FILE) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_COPY_AND_PASTE) {
            // 
            if (!TextUtils.isEmpty(clipboard.getText())) {
                String pasteText = clipboard.getText().toString();
                if (pasteText.startsWith(COPY_IMAGE)) {
                    // ??path
                    sendPicture(pasteText.replace(COPY_IMAGE, ""));
                }

            }
        } else if (requestCode == REQUEST_CODE_ADD_TO_BLACKLIST) { // ???
            EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1));
            addUserToBlacklist(deleteMsg.getFrom());
        } else if (conversation.getMsgCount() > 0) {
            adapter.refresh();
            setResult(RESULT_OK);
        } else if (requestCode == REQUEST_CODE_GROUP_DETAIL) {
            adapter.refresh();
        }

        if (requestCode == REQUEST_CODE_CARD) {
            //????
            String[] newmembers = data.getStringArrayExtra("newmembers");
            LogUtils.i(newmembers.toString(), 1);
            if (newmembers.length > 0) {
                sendCard(EMMessage.ChatType.Chat.ordinal(), newmembers[0], "");
            }
        }
    }
}