代码之家  ›  专栏  ›  技术社区  ›  Sohail Zahid

发送带有多个android图像的彩信

  •  0
  • Sohail Zahid  · 技术社区  · 10 年前

    成功发送包含多个图像的彩信:

    Followed these steps 发送彩信,并在andorid数据库中添加图像。

    问题: 是我有3个图像在1毫米,不知道如何保存他们所有对单一的mms在android数据库。

    我尝试过通过修改给定参考中的方法,在单个彩信中保存多个图像。

    private static Uri createPart(Context context, String id,
                ArrayList<SentMMSVo> sentMMS2) throws Exception {
            ContentValues mmsPartValue = new ContentValues();
            mmsPartValue.put("mid", id);
            mmsPartValue.put("ct", "image/png");
            mmsPartValue.put("cid", "<" + System.currentTimeMillis() + ">");
            Uri partUri = Uri.parse("content://mms/" + id + "/part");
            Uri res = context.getContentResolver().insert(partUri, mmsPartValue);
            Log.e(">>>>>>>", "Part uri is " + res.toString());
    
            for (int i = 0; i < sentMMS2.size(); i++) {
                // Add data to part
                OutputStream os = context.getContentResolver()
                        .openOutputStream(res);
                ByteArrayInputStream is = new ByteArrayInputStream(sentMMS2.get(i)
                        .getData());
                byte[] buffer = new byte[256];
                for (int len = 0; (len = is.read(buffer)) != -1;) {
                    os.write(buffer, 0, len);
                }
                os.close();
                is.close();
            }
            return res;
        }
    

    此方法将保存单个图像。 它保存图像1,然后将新的图像字节覆盖到上一个图像。

    如何在一条彩信中保存多幅图像。

    2 回复  |  直到 6 年前
        1
  •  0
  •   Sohail Zahid    10 年前

    更新找到的解决方案:

    在android数据库中的单个mms中保存多个图像。我只需要这样修改上面的内容。

    逻辑: 我们必须为单个mms创建多个部件。

        private static Uri createPart(Context context, String id,
                    ArrayList<SentMMSVo> sentMMS2) throws Exception {
                ContentValues mmsPartValue = new ContentValues();
                mmsPartValue.put("mid", id);
                mmsPartValue.put("ct", "image/png");
    
    
                for (int i = 0; i < sentMMS2.size(); i++) {
                    // Add data to part
                mmsPartValue.put("cid", "<" + System.currentTimeMillis() + ">");
                Uri partUri = Uri.parse("content://mms/" + id + "/part");
                Uri res = context.getContentResolver().insert(partUri ,mmsPartValue);
                Log.e(">>>>>>>", "Part uri is " + res.toString());
                    OutputStream os = context.getContentResolver()
                            .openOutputStream(res);
                    ByteArrayInputStream is = new ByteArrayInputStream(sentMMS2.get(i)
                            .getData());
                    byte[] buffer = new byte[256];
                    for (int len = 0; (len = is.read(buffer)) != -1;) {
                        os.write(buffer, 0, len);
                    }
                    os.close();
                    is.close();
                }
                return res;
            }
    
        2
  •  -1
  •   Andy the android    10 年前

    这可能会帮助您,本教程演示如何从SD卡发送多个图像。

    https://www.youtube.com/watch?v=55hRGBJ1-2E

    推荐文章