2
这是我的代码,我想将图像附加到电子邮件并发送。transactiontoolargeexception通过电子邮件通过意向发送图像时额外
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);
}
在提到的行中带有注释出错。 如果我得到位图路径,那么我可以通过下面的行我猜...纠正我,如果我错了。希望你能理解我在代码中提到的问题,以便你能帮助我。
intent.putExtra(Intent.ACTION_ATTACH_DATA, bitmapPath);
Aalap,而不是编辑我的答案编辑您的文章与最新的代码和问题,你越来越 –
我更新了我的帖子在这里,错误是在提到的线上。请帮我解决它.. –