Android: How To Send An Image As Email Attachment From Application?
I'm currently trying to create an app that will take a picture and then attach that picture to an email that will be going to a pre determined email address. I have the email work
Solution 1:
publicclassMainActivityextendsActivity {
Button send;
Bitmap thumbnail;
File pic;
EditText address, subject, emailtext;
protectedstaticfinalintCAMERA_PIC_REQUEST=0;
@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
send=(Button) findViewById(R.id.emailsendbutton);
address=(EditText) findViewById(R.id.emailaddress);
subject=(EditText) findViewById(R.id.emailsubject);
emailtext=(EditText) findViewById(R.id.emailtext);
Buttoncamera= (Button) findViewById(R.id.button1);
camera.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(View arg0){
IntentcameraIntent=newIntent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
}
});
send.setOnClickListener(newOnClickListener() {
@OverridepublicvoidonClick(View arg0){
Intenti=newIntent(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_EMAIL, newString[]{"fake@fake.edu"});
i.putExtra(Intent.EXTRA_SUBJECT,"On The Job");
//Log.d("URI@!@#!#!@##!", Uri.fromFile(pic).toString() + " " + pic.exists());
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(pic));
i.setType("image/png");
startActivity(Intent.createChooser(i,"Share you on the jobing"));
}
});
}
protectedvoidonActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST) {
thumbnail = (Bitmap) data.getExtras().get("data");
ImageViewimage= (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap(thumbnail);
try {
Fileroot= Environment.getExternalStorageDirectory();
if (root.canWrite()){
pic = newFile(root, "pic.png");
FileOutputStreamout=newFileOutputStream(pic);
thumbnail.compress(CompressFormat.PNG, 100, out);
out.flush();
out.close();
}
} catch (IOException e) {
Log.e("BROKEN", "Could not write file " + e.getMessage());
}
}
}
Solution 2:
try this
Intenti=newIntent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL , newString[]{"123@gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, " report");
i.putExtra(Intent.EXTRA_TEXT , "PFA");
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(destinationFile));//pngFile
startActivity(Intent.createChooser(i, "Send mail..."));
Solution 3:
try this
send.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(View arg0) {
Intent i = newIntent(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_EMAIL, newString[]{"fake@fake.edu"});
i.putExtra(Intent.EXTRA_SUBJECT, "On The Job");
//Log.d("URI@!@#!#!@##!", Uri.fromFile(pic).toString() + " " + pic.exists());if(pic != null)
{ i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(pic));}
i.setType("image/png");
i.setType("message/rfc822");
startActivity(Intent.createChooser(i, "Share you on the jobing"));
}
});
}
Post a Comment for "Android: How To Send An Image As Email Attachment From Application?"