【问题标题】:"Sorry you cannot add this picture to your message" when attempting to send an MMS尝试发送彩信时“抱歉,您无法将此图片添加到您的信息中”
【发布时间】:2012-11-25 00:20:06
【问题描述】:

我正在尝试发送带有我已保存到 SD 卡的图片的彩信,并且在打开消息服务时,我收到“抱歉,您无法将此图片添加到您的消息中”的声明,并且它没有附加文件。我尝试将文件解析为 uri,尝试将文件直接传递到 MMS 意图中,以及其他一些事情。我不确定我错过了什么,我很确定它正在保存它,因为我可以在文件查看器中看到该文件。我是否必须通过扫描将图像提供给媒体商店(最好不要将其放入图片库),是否必须先打开文件才能将其传入?对我应该做什么的一点指导将不胜感激。

我的文件

private static final String FILENAME = "data.pic";
File dataFile = new File(Environment.getExternalStorageDirectory(), FILENAME);

保存图片

// Selected image id
int position = data.getExtras().getInt("id");
ImageAdapter imageAdapter = new ImageAdapter(this);
ChosenImageView.setImageResource(imageAdapter.mThumbIds[position]);
Resources res = getResources();
Drawable drawable = res.getDrawable(imageAdapter.mThumbIds[position]);
Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] bitmapdata = stream.toByteArray();
try {
    File file = new File(dataFile, FILENAME);
    file.mkdirs();
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(bitmapdata);
    fos.close();
 }catch (FileNotFoundException e) {
 e.printStackTrace();
 } catch (IOException e) {
 e.printStackTrace();
 }

}

我想在哪里附加它以及我当前的尝试

// Create a new MMS intent
Intent mmsIntent = new Intent(Intent.ACTION_SEND);
mmsIntent.putExtra("sms_body", "I sent a pic to you!");
mmsIntent.putExtra("address", txt1);
mmsIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(FILENAME)));
mmsIntent.setType("image/png");
startActivity(mmsIntent);
}};

【问题讨论】:

  • 只要确定文件扩展名private static final String FILENAME = "data.pic";我建议你使用private static final String FILENAME = "data.jpeg";所以它要么"data.jpeg"要么"data.png"
  • 看这里:stackoverflow.com/questions/10527536/… 不同之处在于使用 startActivityForResult() 而不是 startActivity()
  • 嗯将其更改为 data.png (因为它是 png 图像)并且没有运气。
  • @blacharnia 这是我当前尝试使用的参考。我错过了一些东西,无法完全理解它。
  • 看我的回答。希望你能理解。

标签: android save mms


【解决方案1】:

啊抱歉,你不能。

问题:

new File(FILENAME) 不存在。

看看这三个不同的 Files 代码行..

1. File dataFile = new File(Environment.getExternalStorageDirectory(), FILENAME);

2. File file = new File(dataFile, FILENAME);

3. Uri.fromFile(new File(FILENAME))

所有都有不同的参考。

解决方案:

更改您的代码

try {
     File file = new File(dataFile, FILENAME); 
     file.mkdirs(); // You are making a directory here
     FileOutputStream fos = new FileOutputStream(file); // set Outputstream for directory which is wrong
     fos.write(bitmapdata);
     fos.close();
    }catch (FileNotFoundException e) {
     e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

try {
      FileOutputStream fos = new FileOutputStream(dataFile);
      fos.write(bitmapdata);
      fos.close();
     }catch (FileNotFoundException e) {
      e.printStackTrace();
     } catch (IOException e) {
      e.printStackTrace();
    }

以及发送彩信的主要代码行,

if(dataFile.exists())
{
 Intent mmsIntent = new Intent(Intent.ACTION_SEND);
     mmsIntent.putExtra("sms_body", "I sent a pic to you!");
     mmsIntent.putExtra("address", txt1);
     mmsIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(dataFile));
     mmsIntent.setType("image/png");
     startActivity(mmsIntent);
}

您的所有代码只需使用一个 dataFile File 引用。

【讨论】:

  • 在发送图像之前检查它是否存在于外部存储中。
  • 非常感谢,我是新手,犯了一个菜鸟错误,哈哈,现在看到问题了。在您的帮助下设法使其正确附加文件,但现在在 MMS 中显示图像似乎有问题。它显示了一个带有“!”的三角形的通用图像在其中,似乎它现在没有正确转换它。 (还想在添加检查外部是否可用之前使基本功能正常工作,将添加它)。
  • @user1409172 可以通过彩信发送音频或视频吗?我在通过 mms 发送音频文件时遇到问题,仅适用于 htc、lava 或某些三星等少数设备。
猜你喜欢
  • 2017-06-12
  • 1970-01-01
  • 1970-01-01
  • 2015-10-07
  • 1970-01-01
  • 1970-01-01
  • 2018-12-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多