Aru*_*ole 2 android email-attachments android-intent
我想将多个文件附加到电子邮件中.
首先,我准备了一份清单Uri.
void prepareListOfUri()
{
listOfUri = new ArrayList<Uri>();
File fileTemp = new File(android.os.Environment.getExternalStorageDirectory(), "BuyNowImages");
fileTemp.mkdirs();
for (int i = 0; i < listOfImageView.size(); i++)
{
try
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Drawable drawable = listOfImageView.get(i).getDrawable();
Bitmap bitmapPicked = ((BitmapDrawable) drawable).getBitmap();
bitmapPicked.compress(CompressFormat.JPEG, 75, bos);
byte[] image = bos.toByteArray();
File file = new File(fileTemp, "buynow_product" + i + ".jpg");
file.createNewFile();
// write the bytes in file
FileOutputStream fo = new FileOutputStream(file);
fo.write(image);
Uri uri = Uri.parse("file://" + file.getAbsolutePath());
listOfUri.add(i, uri);
} catch (Exception e)
{
// TODO: handle exception
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
并附加和发送电子邮件
void sendMultipleAttachments()
{
try
{
Intent intentEmail = new Intent(Intent.ACTION_SEND);
intentEmail.setType("text/plain");
String[] recipients = new String[] { "" };
intentEmail.putExtra(Intent.EXTRA_EMAIL, recipients);
intentEmail.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
intentEmail.putExtra(Intent.EXTRA_TEXT, "body of email");
intentEmail.setType("image/jpeg");
intentEmail.putParcelableArrayListExtra(Intent.EXTRA_STREAM, listOfUri);
startActivity(intentEmail);
} catch (android.content.ActivityNotFoundException ex)
{
Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
ex.printStackTrace();
} catch (Exception e)
{
e.printStackTrace();
Toast.makeText(this, "Exception " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
Run Code Online (Sandbox Code Playgroud)
我已经Uri通过单独发送每个文件检查了s 的列表.但是,通过使用上面的代码发送多个文件,我获得以下Exception.
Key android.intent.extra.STREAM expected Parcelable but value was a java.util.ArrayList. The default value <null> was returned.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1806 次 |
| 最近记录: |