I'm developing an app, where i'm generating an image using EditText field( textArea.setDrawingCacheEnabled(true); textArea.buildDrawingCache(true); ) and saving it on SD card. And at the same time i wanted that image to be shared between other apps using ACTION_SEND intent. Here the problem i'm facing is i'm able to generate the image from EditText but the same image is not getting attached to the intent(share intent in this example), please tell me where i'm going wrong..
Thanks in advance..
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
File picDir = new File(Environment.getExternalStorageDirectory()
+ "/myPic");
if (!picDir.exists()) {
picDir.mkdir();
}
textArea.setDrawingCacheEnabled(true);
textArea.buildDrawingCache(true);
Bitmap bitmap = textArea.getDrawingCache();
Date date = new Date();
String fileName = "img" + date.getTime() + ".png";
File picFile = new File(picDir + "/" + fileName);
try {
picFile.createNewFile();
FileOutputStream picOut = new FileOutputStream(picFile);
boolean saved = bitmap.compress(CompressFormat.PNG, 100,
picOut);
if (saved) {
Toast.makeText(
getApplicationContext(),
"Image saved to your device Pictures "
+ "directory!", Toast.LENGTH_SHORT).show();
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(Environment.getExternalStorageDirectory() +"/" +picFile));
startActivity(Intent.createChooser(share, "Send picture using:"));
} else {
//Error
}
picOut.close();
} catch (Exception e) {
e.printStackTrace();
}
textArea.destroyDrawingCache();
} else {
//Error
}
Here is what I am using for attaching files to an email :
This should do the trick for you.