insert Vodafone sim card,open the mms read report,when receive the read report,cann't download the message

Test steps:

1.insert Vodafone sim card

2.open the mms read report

3.send the mms successfully

4.when receive the read report

这里的环境须要描写叙述一下:在国内不会出现这个问题,该问题在土耳其測试发现,经过分析主要因国内外网络差异导致。

问题大概意思是在国外发送一条彩信。对方成功接收。发送方測试会接收一条阅读报告。

该阅读报告是以彩信的方式接收。这个时候问题来了。彩信无法自己主动下载,点击下载button也无法完毕下载(这里从界面时的确能够这么理解,分析代码之后才发现彩信数据已经下载成功,仅仅是在解析的时候格式不兼容导致解析发生异常,返回null。

因此经过分析打开NotificationTransaction.java中的log,从log中得到已经下载好的彩信数据,然后在国内用此模拟数据来解决这个问题。

if (retrieveConfData != null) {(这里加入凝视的意思也就是在这里输出log,得到国外模拟数据,然后在国内进行模拟測试)

                //if (Log.isLoggable(LogTag.TRANSACTION, Log.DEBUG)) {

                    Log.v(TAG, "NotificationTransaction: retrieve data=" +

                            HexDump.dumpHexString(retrieveConfData));//HexDump这个工具类非常重要。假设有时间大家细致阅读一下源代码(能够将16进制字符串和字节数组进行转换)

//}

当然,终于改动解决这个问题的实在解析pdu和持久化保存的PduParser.java类。

case PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF:

                if (LOCAL_LOGV) {

                    Log.v(LOG_TAG, "parse: MESSAGE_TYPE_RETRIEVE_CONF");

                }

                RetrieveConf retrieveConf =

                    new RetrieveConf(mHeaders, mBody);



                byte[] contentType = retrieveConf.getContentType();

                if (null == contentType) {

                    if (LOCAL_LOGV)

                        Log.v(LOG_TAG, "contentType is null");

                    return null;

                }

                String ctTypeStr = new String(contentType);

                if (LOCAL_LOGV)

                    Log.v(LOG_TAG, "ctTypeStr is l"+ctTypeStr);

                if (ctTypeStr.equals(ContentType.MULTIPART_MIXED)

                        || ctTypeStr.equals(ContentType.MULTIPART_RELATED)

                        || ctTypeStr.equals(ContentType.TEXT_PLAIN)//这里是加入对“text/plain”格式彩信的兼容

                        || ctTypeStr.equals(ContentType.MULTIPART_ALTERNATIVE)) {

                    // The MMS content type must be "application/vnd.wap.multipart.mixed"

                    // or "application/vnd.wap.multipart.related"

                    // or "application/vnd.wap.multipart.alternative"

                    return retrieveConf;

                } else if (ctTypeStr.equals(ContentType.MULTIPART_ALTERNATIVE)) {

                    // "application/vnd.wap.multipart.alternative"

                    // should take only the first part.

                    PduPart firstPart = mBody.getPart(0);

                    mBody.removeAll();

                    mBody.addPart(0, firstPart);

                    return retrieveConf;

                }

                return null;

以下这发现异常的时候忽视异常:

protected static PduBody parseParts(ByteArrayInputStream pduDataStream) {

        if (pduDataStream == null) {

            if (LOCAL_LOGV)

                Log.v(LOG_TAG, "pduDataStream is null");

            return null;

        }



        int count = parseUnsignedInt(pduDataStream); // get the number of parts

        PduBody body = new PduBody();



        for (int i = 0 ; i < count ; i++) {

            int headerLength = parseUnsignedInt(pduDataStream);

            int dataLength = parseUnsignedInt(pduDataStream);

            PduPart part = new PduPart();

            int startPos = pduDataStream.available();

            if (startPos <= 0) {

                // Invalid part.

                return body;//这里原本是返回null

            }




            /* parse part's content-type */

            HashMap<Integer, Object> map = new HashMap<Integer, Object>();

            byte[] contentType = parseContentType(pduDataStream, map);

            if (null != contentType) {

                part.setContentType(contentType);

            } else {

                if (LOCAL_LOGV)

                    Log.v(LOG_TAG, "contentType isn't null");

                part.setContentType((PduContentTypes.contentTypes[0]).getBytes()); //"*/*"

            }



            /* get name parameter */

            byte[] name = (byte[]) map.get(PduPart.P_NAME);

            if (null != name) {

                part.setName(name);

            }

            else{

                if (LOCAL_LOGV)

                    Log.v(LOG_TAG, "name isn't null");

            }

            /* get charset parameter */

            Integer charset = (Integer) map.get(PduPart.P_CHARSET);

            if (null != charset) {

                part.setCharset(charset);

            }

            else{

                if (LOCAL_LOGV)

                    Log.v(LOG_TAG, "charset isn't null");

            }

            /* parse part's headers */

            int endPos = pduDataStream.available();

            int partHeaderLen = headerLength - (startPos - endPos);

            if (partHeaderLen > 0) {

                if (false == parsePartHeaders(pduDataStream, part, partHeaderLen)) {

                    // Parse part header faild.

                    if (LOCAL_LOGV)

                        Log.v(LOG_TAG, "Parse part header faild.");

                    //return null;

                }

            } else if (partHeaderLen < 0) {

                // Invalid length of content-type.

                if (LOCAL_LOGV)

                    Log.v(LOG_TAG, "Invalid length of content-type.");

                //return null;

            }



            /* FIXME: check content-id, name, filename and content location,

             * if not set anyone of them, generate a default content-location

             */

            if ((null == part.getContentLocation())

                    && (null == part.getName())

                    && (null == part.getFilename())

                    && (null == part.getContentId())) {

                part.setContentLocation(Long.toOctalString(

                        System.currentTimeMillis()).getBytes());

            }



            /* get part's data */

            if (dataLength > 0) {

                byte[] partData = new byte[dataLength];

                String partContentType = new String(part.getContentType());

                pduDataStream.read(partData, 0, dataLength);

                if (partContentType.equalsIgnoreCase(ContentType.MULTIPART_ALTERNATIVE)) {

                    // parse "multipart/vnd.wap.multipart.alternative".

                    PduBody childBody = parseParts(new ByteArrayInputStream(partData));

                    // take the first part of children.

                    part = childBody.getPart(0);

                } else {

                    // Check Content-Transfer-Encoding.

                    byte[] partDataEncoding = part.getContentTransferEncoding();

                    if (null != partDataEncoding) {

                        String encoding = new String(partDataEncoding);

                        if (encoding.equalsIgnoreCase(PduPart.P_BASE64)) {

                            // Decode "base64" into "binary".

                            partData = Base64.decodeBase64(partData);

                        } else if (encoding.equalsIgnoreCase(PduPart.P_QUOTED_PRINTABLE)) {

                            // Decode "quoted-printable" into "binary".

                            partData = QuotedPrintable.decodeQuotedPrintable(partData);

                        } else {

                            // "binary" is the default encoding.

                        }

                    }

                    else{

                        if (LOCAL_LOGV)

                            Log.v(LOG_TAG, "partDataEncoding isn't null");

                    }

                    if (null == partData) {

                        log("Decode part data error!");

                        return null;

                    }

                    else{

                        if (LOCAL_LOGV)

                            Log.v(LOG_TAG, "partData isn't null");

                    }

                    part.setData(partData);

                }

            }



            if(LOCAL_LOGV)

                Log.v(LOG_TAG,"checkPartPosition is "+checkPartPosition(part));

            /* add this part to body */

            if (THE_FIRST_PART == checkPartPosition(part)) {

                /* this is the first part */

                body.addPart(0, part);

            } else {

                /* add the part to the end */

                body.addPart(part);

            }

        }



        return body;

    }

版权声明:本文博主原创文章,博客,未经同意不得转载。

最新文章

  1. 泛型T的类型获取
  2. HTML的ul和li标签的使用
  3. 第九回 Microsoft.Practices.Unity.Interception实现基于数据集的缓存(针对六,七,八讲的具体概念和配置的解说)
  4. spring 第一篇(1-1):让java开发变得更简单(下)转
  5. gitlab web登入密码忘记以后可以用如下方式修改密码
  6. nginx gzip 模块配置
  7. 【转】从开发者的角度看待各移动平台 ios/android/wp7/win8ost title
  8. Sort List (使用归并排序的链表排序)
  9. RHEL6.4 postfix+dovecot搭建邮件服务器
  10. 【IE6的疯狂之十】父级使用padding后子元素绝对定位的BUG
  11. jquery楼层效果
  12. 转 jquery获取两个标签之间文本
  13. css之transform属性
  14. FileInputStream.FileOutputStream执行图片复制
  15. 一般处理程序HttpHandler的应用
  16. C# System.IO.Path
  17. SQL Server 调优系列基础篇 - 联合运算符总
  18. c#之using关键字
  19. Popular Cows---poj2186(缩点,强联通)
  20. CSS基础知识,学前准备

热门文章

  1. 把git仓库从码云迁到github,及git常用命令
  2. SQL Server 2008 Tempdb 数据库迁移
  3. Win10系统如何设置所有程序默认以管理员身份运行?
  4. php对xml进行简单的增删改查(CRUD)操作
  5. 链表(三)——链表删除冗余结点&amp;amp;插入结点到有序链表
  6. FeatureLayer,FeatureDataset,FeatureClass,Feature的区别与联系总结
  7. [RxJS] Multicast with a selector argument, as a sandbox
  8. [Recompose] Flatten a Prop using Recompose
  9. js课程 1-5 js如何测试变量的数据类型
  10. 益智小游戏(app)