从应用程序拍照并将其发送到电子邮件(Android)

时间:2016-10-02 14:37:38

标签: java android android-studio android-camera android-file

我需要在我的Android应用程序中拍摄设置为ImageView的照片,并在按钮后单击打开电子邮件应用程序并将此照片作为附件。

File photoFile;

按钮拍摄照片事件:

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
    startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}

活动结果:

if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
    Bundle extras = data.getExtras();
    Bitmap imageBitmap = (Bitmap) extras.get("data");
    imageView.setImageBitmap(imageBitmap);

    //photoFile how to set path of imageBitmap ?
 }

并发送无效的电子邮件按钮...(java.lang.NullPointerException:file)

Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"fake@fake.edu"});
intent.putExtra(Intent.EXTRA_SUBJECT,"On The Job");

intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(photoFile));

intent.setType("image/png");
startActivity(Intent.createChooser(intent,"Share you on the jobing"));

0 个答案:

没有答案