[英]Attaching an image to an email via android app
我的應用成功制作了電子郵件,但當我嘗試附加圖片時,代碼崩潰就是代碼片段
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"email address"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
// i.putExtra(Intent.EXTRA_STREAM, R.drawable.pic4);
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(EidCards.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
評論的行使代碼崩潰請建議出路!
這對你不起作用:
i.putExtra(Intent.EXTRA_STREAM, R.drawable.pic4);
R.drawable.pic4的類型是什么? 這不是用於解析drawable的整數嗎?
了解其他人如何附加圖片: 使用Intent.ACTION_SEND和Intent.EXTRA_STREAM與Google+應用分享圖片
這很簡單:P
Intent i = new Intent(Intent.ACTION_SEND);
int imageURI=R.drawable.pic4;
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"email address"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
i.putExtra(Intent.EXTRA_STREAM, R.drawable.pic4);
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://"+getPackageName()+"/"+imageURI));
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(EidCards.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.