I want to send screenshot via email. Below is how i manage to take screenshot and save in directory. What i want is to not save but send directly. How can i achieve it?
public Bitmap takeScreenshot() {
View rootView = getWindow().getDecorView().findViewById(R.id.relative);
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();
}
public void saveBitmap(Bitmap bitmap) {
String root = Environment.getExternalStorageDirectory().toString();
File newDir = new File(root + "/MapCards");
newDir.mkdirs();
Random gen = new Random();
int n = 10000;
n = gen.nextInt(n);
String fotoname = "MapCard-" + n + ".jpg";
File file = new File(newDir, fotoname);
if (file.exists())
file.delete();
try {
FileOutputStream fos = new FileOutputStream(file);
bitmap.compress(CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
Toast.makeText(getApplicationContext(),
"Saved in folder: 'MapCards'", Toast.LENGTH_SHORT).show();
} catch (FileNotFoundException e) {
Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}
}
Maybe i need to add something like below, after i take the screenshot but i am not sure how to configure it together.
public void send() {
String temp = getIntent().getStringExtra("picture_path");
URI = Uri.parse("file://" + temp);
final Intent emailIntent = new Intent(
android.content.Intent.ACTION_SEND);
emailIntent.setType("image/jpeg");
if (URI != null) {
emailIntent.putExtra(Intent.EXTRA_STREAM, URI);
}
this.startActivity(Intent.createChooser(emailIntent,
"Send email using.."));
}
Thank you for help.