电子邮件发送意向文本文件,而不是像 [英] Email Intent sends text file rather than image
问题描述
这在code我使用采取图片,显示它,然后通过电子邮件发送的:
This the code I am using to take picture, display it, then send it in an email:
private void takePicture() {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File photo = new File(Environment.getExternalStorageDirectory(),
getIntent().getStringExtra("counter"));
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
imageUri = Uri.fromFile(photo);
startActivityForResult(intent, 0);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 0:
if (resultCode == Activity.RESULT_OK) {
Uri selectedImage = imageUri;
getContentResolver().notifyChange(selectedImage, null);
ContentResolver cr = getContentResolver();
try {
bitmap = android.provider.MediaStore.Images.Media
.getBitmap(cr, selectedImage);
savePicture(getIntent().getStringExtra("counter"), bitmap,
getApplicationContext());
setImage();
Toast.makeText(this, selectedImage.toString(), Toast.LENGTH_LONG).show();
} catch (Exception e) {
}
}
}
}
我如何发送电子邮件:
How I send the email:
final Intent emailIntent = new Intent(
android.content.Intent.ACTION_SEND);
String fileName = null;
try {
fileName = URLEncoder.encode(getIntent().getStringExtra("counter"), "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String path = Environment.getExternalStorageDirectory()+"/"+fileName.trim().toString();
Uri uri = Uri.parse("file://"+path);
emailIntent.setType("image/png");
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, uri);
/* Send it off to the Activity-Chooser */
startActivity(Intent
.createChooser(emailIntent, "Send Email..."));
注意,我的文件名应该是 getIntent()getStringExtra(反);
Notice, my file name should be getIntent().getStringExtra("counter");
当我这样做,我的电子邮件发送一个文本文件,而不是一个图像文件。我不知道为什么它这样做...
When I do this, my email sends a text file rather than an image file. I have no clue why it does this...
推荐答案
我怀疑这发生在一个以上的人,但问题是这样的:
I suspect this has happened to more than one person, but the problem was this:
我不得不 +。JPG
添加以文件名的结尾,而现在它的作品。这可能是一个简单的解决方案,但它肯定是一个痛苦的问题!
I had to add +".jpg"
to the end of the filename, and now it works. This may have been a simple solution but it surely was a distressful problem!
希望这篇文章仍然帮助那些谁在将来遇到此问题。
Hope this post still helps those who encounter this issue in the future.
这篇关于电子邮件发送意向文本文件,而不是像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!