我想通过电子邮件发送截图。以下是我如何设置截屏并保存在目录中。我想要的是不保存但直接发送。我怎样才能实现它?
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);
}
}
也许我需要添加类似下面的东西,在我拍摄截图后但我不确定如何配置它。
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.."));
}
感谢您的帮助。
答案 0 :(得分:0)
我的工作代码。请试试。
final File file = getTempPictureFile();
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType(HTTP.PLAIN_TEXT_TYPE);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, Constants.EMAIL_SUBJECT);
emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(Constants.EMAIL_BODY_MSG));
if(file != null)
{
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
}
startActivity(Intent.createChooser(emailIntent, Constants.CHOOSE_EMAIL_CLIENT));