首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从MMS中获取图像会产生错误的MMS

从MMS中获取图像会产生错误的MMS
EN

Stack Overflow用户
提问于 2014-11-24 10:43:25
回答 1查看 239关注 0票数 1

我的应用程序试图从设备中获取SMS和MMS,并将其存储在数据库中。我已经尝试过这样的代码:How to Read MMS Data in Android? --它运行得很好,但是问题是获取错误的MMS映像。当我在备份MMS的同时发送一个新的MMS时,这种情况就会发生。这是我的代码:

代码语言:javascript
复制
// To get text content from mms..
    public ArrayList<String> getMmsTextContent(String mmsId) {
        String body = null;
        ArrayList<String> arlMMS = new ArrayList<String>();
        String selectionPart = "mid=" + mmsId;
        Uri uri = Uri.parse("content://mms/part");
        Cursor cursor = getContentResolver().query(uri, null, selectionPart,
                null, null);
        if (cursor.moveToFirst()) {
            do {
                String partId = cursor.getString(cursor.getColumnIndex("_id"));
                String type = cursor.getString(cursor.getColumnIndex("ct"));
                if ("text/plain".equals(type)) {
                    String data = cursor.getString(cursor
                            .getColumnIndex("_data"));

                    if (data != null) {
                        // implementation of this method below
                        body = getMmsText(partId);
                        arlMMS.add(body);
                    } else {
                        body = cursor.getString(cursor.getColumnIndex("text"));
                        arlMMS.add(body);
                    }
                }
            } while (cursor.moveToNext());
            return arlMMS;
        }
        return null;
    }

    // To get the text
    private String getMmsText(String id) {
        Uri partURI = Uri.parse("content://mms/part/" + id);
        InputStream is = null;
        StringBuilder sb = new StringBuilder();
        try {
            is = getContentResolver().openInputStream(partURI);
            if (is != null) {
                InputStreamReader isr = new InputStreamReader(is, "UTF-8");
                BufferedReader reader = new BufferedReader(isr);
                String temp = reader.readLine();
                while (temp != null) {
                    sb.append(temp);
                    temp = reader.readLine();
                }
            }
        } catch (IOException e) {
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                }
            }
        }
        return sb.toString();
    }

    // To get the mms..
    public ArrayList<Bitmap> getMms(String mmsId) {
        Bitmap bitmap = null;
        ArrayList<Bitmap> arlBitmap = new ArrayList<Bitmap>();
        String selectionPart = "mid=" + mmsId;
        Uri uri = Uri.parse("content://mms/part");
        Cursor cPart = getContentResolver().query(uri, null, selectionPart,
                null, null);
        if (cPart.moveToFirst()) {
            do {
                String partId = cPart.getString(cPart.getColumnIndex("_id"));
                String type = cPart.getString(cPart.getColumnIndex("ct"));
                if ("image/jpeg".equals(type) || "image/bmp".equals(type)
                        || "image/gif".equals(type) || "image/jpg".equals(type)
                        || "image/png".equals(type)) {
                    bitmap = getMmsImage(partId);
                    arlBitmap.add(bitmap);
                }
            } while (cPart.moveToNext());

            return arlBitmap;
        }
        return arlBitmap;
    }

    // To get bitmap from mms
    private Bitmap getMmsImage(String _id) {
        Uri partURI = Uri.parse("content://mms/part/" + _id);
        InputStream is = null;
        Bitmap bitmap = null;
        try {
            is = getContentResolver().openInputStream(partURI);
            bitmap = BitmapFactory.decodeStream(is);
        } catch (IOException e) {
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                }
            }
        }
        return bitmap;
    }
}

请帮帮我。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-23 07:21:29

每次运行两个线程,一个是备份映像,另一个是从sqlite检索映像。更改两个不同的文件夹可以消除此问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27102920

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档