拍照,裁剪,然后发送图像作为电子邮件意图

时间:2012-11-08 17:30:21

标签: android android-intent

我已经在这3天了,但仍然没有运气。我正在尝试拍照,裁剪它,然后通过意图在Android上发送电子邮件。

到目前为止,我可以拍摄照片并裁剪它。但是,当我尝试设置电子邮件部分时,一旦拍摄照片,电子邮件意图就会立即弹出并且不允许我裁剪。 (如果我点击gmail,则播种在后台)。

到目前为止,我已经尝试过:

        @Override
    public void onPictureTaken(byte[] arg0, Camera arg1) {

        //Bitmap bitmapPicture = BitmapFactory.decodeByteArray(arg0, 0, arg0.length);   



        OutputStream imageFileOS;
        try {
            imageFileOS = getContentResolver().openOutputStream(uriTarget);
            imageFileOS.write(arg0);
            imageFileOS.flush();
            imageFileOS.close();

            Toast.makeText(DigitalSignature.this, 
                    "Image saved: " + uriTarget.toString(), 
                    Toast.LENGTH_LONG).show();

            String[] recipients = new String[]{"digital.signature@lads.jetdelivery.com", "",};


            Intent intent = new Intent("com.android.camera.action.CROP");
            // this will open all images in the Galery
            intent.setDataAndType(uriTarget, "image/jpeg");
            intent.putExtra("crop", "true");
            // this defines the aspect ration
            intent.putExtra("aspectX", 20);
            intent.putExtra("aspectY", 0);
            // this defines the output bitmap size
            //intent.putExtra("outputX", 256);
            //intent.putExtra("outputY", 256);

            // true to return a Bitmap, false to directly save the cropped iamge
            intent.putExtra("return-data", false);
            //save output image in uri
            intent.putExtra(MediaStore.EXTRA_OUTPUT, uriTarget);
            startActivity(intent);


            Intent intent2 = new Intent(Intent.ACTION_SEND);
            intent2.setType("image/jpeg");
            intent2.putExtra(Intent.EXTRA_EMAIL, recipients);
            intent2.putExtra(Intent.EXTRA_SUBJECT, job);
            intent.putExtra(Intent.EXTRA_STREAM, uriTarget.getPath()); // Attaches image to Gmail


              //File shareImg =  new File(uriTarget);
              //intent.putExtra(Intent.EXTRA_STREAM, uriTarget.fromFile(shareImg));

            try {
                startActivity(intent2);

            } catch (android.content.ActivityNotFoundException ex) {

                Toast.makeText(DigitalSignature.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
            }

有人能帮我指引正确的方向吗?

谢谢,约翰。

1 个答案:

答案 0 :(得分:0)

您必须{C}意图startActivityForResult,并在收到结果后通过电子邮件发送。