首页 > 代码库 > 解决在转发一条内容为满的彩信,删除主题FWD,发送的时候提示转化为短信。

解决在转发一条内容为满的彩信,删除主题FWD,发送的时候提示转化为短信。

问题描述:

1.长按一条输入内容为满的彩信,选择转发
2.输入联系人-删除主题FWD-发送

测试结果为:提示正转化为短信(见附件)
预期结果为:不应该有提示,应该还是彩信

测试结果图为:






根据提示的Toast内容“Converting to text message...”进行代码最终进行代码定位到ComposeMessageActivity类的showConvertToSmsToast()方法,并打印堆栈:

    private void showConvertToSmsToast() {
        Log.d("bill",Log.getStackTraceString(new Throwable()));
        Toast.makeText(this, R.string.converting_to_text_message, Toast.LENGTH_SHORT).show();
    }




通过打印堆栈我们可以看出方法的调用流程,我们从下往上来分析到底是哪一个环节除了问题,首先分析ComposeMessageActivity类的onProtocolChanged()方法:


    @Override
    public void onProtocolChanged(final boolean convertToMms) {<TAG 1-1>
        // Have to make sure we‘re on the UI thread. This function can be called off of the UI
        // thread when we‘re adding multi-attachments
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (mShowTwoButtons) {
                    showTwoSmsOrMmsSendButton(convertToMms);
                } else {
                    showSmsOrMmsSendButton(convertToMms);
                }


                if (convertToMms) {
                    // In the case we went from a long sms with a counter to an mms because
                    // the user added an attachment or a subject, hide the counter --
                    // it doesn‘t apply to mms.
                    mTextCounter.setVisibility(View.GONE);

                    if (mShowTwoButtons) {
                        mTextCounterSec.setVisibility(View.GONE);
                    }
                    showConvertToMmsToast();
                } else {
                    mTextCounter.setVisibility(View.VISIBLE);
                    showConvertToSmsToast();
                }
            }
        });
   
从上面代码我们分析,当彩信已经发送的时候,该方法不应该在调用,而是应该在输入短息内容的时候进行调用。那我们接着分析WorkingMessage类的updateState()方法,setSubject()方法,removeSubjectIfEmpty()方法,send()方法和sendMessage()方法。

    private void updateState(int state, boolean on, boolean notify) {<TAG1-2>
        if (!sMmsEnabled) {
            // If Mms isn‘t enabled, the rest of the Messaging UI should not be using any
            // feature that would cause us to to turn on any Mms flag and show the
            // "Converting to multimedia..." message.
            return;
        }
        int oldState = mMmsState;
        if (on) {
            mMmsState |= state;
        } else {
            mMmsState &= ~state;
        }

        // If we are clearing the last bit that is not FORCE_MMS,
        // expire the FORCE_MMS bit.
        if (mMmsState == FORCE_MMS && ((oldState & ~FORCE_MMS) > 0)) {
            mMmsState = 0;
        }

        // Notify the listener if we are moving from SMS to MMS
        // or vice versa.
        if (notify) {
            if (oldState == 0 && mMmsState != 0) {
                mStatusListener.onProtocolChanged(true);
            } else if (oldState != 0 && mMmsState == 0) {
                mStatusListener.onProtocolChanged(false);
            }
        }

        if (oldState != mMmsState) {
            if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) LogTag.debug("updateState: %s%s = %s",
                    on ? "+" : "-",
                    stateString(state), stateString(mMmsState));
        }
    }

    public void setSubject(CharSequence s, boolean notify) {<TAG 1-3>
        mSubject = s;
        updateState(HAS_SUBJECT, (s != null), notify);
        if (mSlideshow != null) {
            mSlideshow.setSubjectSize((s == null) ? 0 : s.toString().getBytes().length);
        }
    }

    private void removeSubjectIfEmpty(boolean notify) {<TAG1-4>
        if (!hasSubject()) {
            setSubject(null, notify);
        }
    }

    public void send(final String recipientsInUI) {<TAG1-5>
        long origThreadId = mConversation.getThreadId();

        if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
            LogTag.debug("send origThreadId: " + origThreadId);
        }

        removeSubjectIfEmpty(true /* notify */);

        // Get ready to write to disk.
        prepareForSave(true /* notify */);

        // We need the recipient list for both SMS and MMS.
        final Conversation conv = mConversation;
        String msgTxt = mText.toString();

        if (requiresMms() || addressContainsEmailToMms(conv, msgTxt)) {
            // uaProfUrl setting in mms_config.xml must be present to send an MMS.
            // However, SMS service will still work in the absence of a uaProfUrl address.
            if (MmsConfig.getUaProfUrl() == null) {
                String err = "WorkingMessage.send MMS sending failure. mms_config.xml is " +
                        "missing uaProfUrl setting.  uaProfUrl is required for MMS service, " +
                        "but can be absent for SMS.";
                RuntimeException ex = new NullPointerException(err);
                Log.e(TAG, err, ex);
                // now, let‘s just crash.
                throw ex;
            }

            // Make local copies of the bits we need for sending a message,
            // because we will be doing it off of the main thread, which will
            // immediately continue on to resetting some of this state.
            final Uri mmsUri = mMessageUri;
            final PduPersister persister = PduPersister.getPduPersister(mActivity);

            final SlideshowModel slideshow = mSlideshow;
            final CharSequence subject = mSubject;
            final boolean textOnly = mAttachmentType == TEXT;

            if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
                LogTag.debug("Send mmsUri: " + mmsUri);
            }

            // Do the dirty work of sending the message off of the main UI thread.
            new Thread(new Runnable() {
                @Override
                public void run() {
                    final SendReq sendReq = makeSendReq(conv, subject);

                    // Make sure the text in slide 0 is no longer holding onto a reference to
                    // the text in the message text box.
                    slideshow.prepareForSend();
                    sendMmsWorker(conv, mmsUri, persister, slideshow, sendReq, textOnly);

                    updateSendStats(conv);
                }
            }, "WorkingMessage.send MMS").start();
        } else {
            // Same rules apply as above.
            // add user‘s signature first if this feature is enabled.
            String text = mText.toString();
            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mActivity);
            if (sp.getBoolean("pref_key_enable_signature", false)) {
                String signature = (sp.getString("pref_key_edit_signature", "")).trim();
                if (signature.length() > 0) {
                    String sigBlock = "\n" + signature;
                    if (!text.endsWith(sigBlock)) {
                        // Signature should be written behind the text in a
                        // newline while the signature has changed.
                        text += sigBlock;
                    }
                }
            }
            final String msgText = text;
            new Thread(new Runnable() {
                @Override
                public void run() {
                    preSendSmsWorker(conv, msgText, recipientsInUI);

                    updateSendStats(conv);
                }
            }, "WorkingMessage.send SMS").start();
        }

        // update the Recipient cache with the new to address, if it‘s different
        RecipientIdCache.updateNumbers(conv.getThreadId(), conv.getRecipients());

        // Mark the message as discarded because it is "off the market" after being sent.
        mDiscarded = true;
    }


通过对上述代码<TAG 1-3>的方法分析发现,将下划线代码进行注释,也就是说在彩信已经进行发送的时候不再更新状态。问题解决。