【问题标题】:transactiontoolargeexception while sending image via email through intent extra通过意图额外的电子邮件通过电子邮件发送图像时出现transactiontoolargeexception
【发布时间】:2015-12-03 06:09:57
【问题描述】:

这是我想将图像附加到电子邮件并发送的代码。

    String receiverEmail = receiver.getText().toString().trim();
    String to[] = {receiverEmail};
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setData(Uri.parse("mailto:"));
    intent.setType("imge/jpeg");
    intent.putExtra(Intent.EXTRA_EMAIL, to);
    intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
    intent.putExtra(Intent.EXTRA_TEXT, "hello wats up");
    intent.putExtra(Intent.EXTRA_STREAM, bitmap );
    startActivity(intent);

我收到错误提示

Caused by: android.os.TransactionTooLargeException: data parcel size 1331968 bytes

此问题与位图文件有关。如何减小尺寸。? 帮我解决这个问题。提前谢谢你。

{
oncreate method....
I have my bitmap here created with instance name bitmap which i want to send in email attachment
Uri bitmapUri = getImageUri(OutgoingEmbededImage.this, bitmap); //null pointer exception error here
String bitmapPath = getPathOfUri(bitmapUri);
end of on create method
}

//getting bitmapUri here 
 private Uri getImageUri(Context context, Bitmap myBitmap){
 ByteArrayOutputStream bytes = new ByteArrayOutputStream();
 myBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
 String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), myBitmap, "Image", null);
 return Uri.parse(path);
}

//string path here
public String getPathOfUri(Uri uri){
    Cursor cursor = getContentResolver().query(uri, null, null, null, null);
    cursor.moveToFirst();
    int index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
    return cursor.getString(index);
}

使用 cmets 在提到的行上出现错误。 如果我得到位图路径,那么我可以在下面的行中传递它……如果我错了,请纠正我。并希望您能理解我在代码中提到的问题,以便您能帮助我。

intent.putExtra(Intent.ACTION_ATTACH_DATA, bitmapPath);

【问题讨论】:

  • Aalap,而不是编辑我的答案,用你得到的最新代码和问题编辑你的帖子
  • 我在这里更新了我的帖子,错误就在提到的那一行。请帮我解决它..

标签: android android-layout android-fragments android-intent


【解决方案1】:

这里:

intent.putExtra(Intent.EXTRA_STREAM, bitmap );

行导致问题,因为bitmap 的大小非常大,允许的 Binder 事务缓冲区大小。

看这里:

TransactionTooLargeException

Binder 事务缓冲区有一个有限的固定大小,目前为 1Mb, 该进程的所有正在进行的事务共享。 因此,当有很多 即使大多数个别交易仍在进行中 大小适中。

因此,要解决此问题,而不是使用 Intent.putExtra 传递图像的位图,请使用 图像 url,file path,URI,Drawable id,... 发送最小尺寸数据。 p>

【讨论】:

    猜你喜欢
    • 2013-02-21
    • 2018-09-20
    • 1970-01-01
    • 2012-04-24
    • 2013-12-01
    • 2015-10-26
    • 1970-01-01
    • 2013-10-10
    • 2018-04-08
    相关资源
    最近更新 更多