如何从电子邮件应用程序中的收件人地址中删除文件提供者地址?

时间:2019-06-30 19:06:51

标签: android-camera email-attachments android-camera-intent android-fileprovider fileprovider

我正在尝试自动将捕获的图像附加到邮件中。但是,问题在于,与图像一起,其文件提供者地址也会显示在接收者的地址中。如何删除它?

MainActivity.java

//code to send an email along with the image automatically attached to it
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"xyz123@gmail.com"});
                intent.putExtra(Intent.EXTRA_SUBJECT, "Details");
                intent.putExtra(Intent.EXTRA_TEXT, Details);
                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                intent.setDataAndType(photoUri, "image/*");
                intent.putExtra(Intent.EXTRA_STREAM, photoUri);
                if (intent.resolveActivity(getPackageManager()) != null) {
                    startActivity(Intent.createChooser(intent, "Shared"));
                }

//code to capture image from android camera
private void dispatchPictureTakeAction() {
        Intent takePic = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (takePic.resolveActivity(getPackageManager()) != null) {
            File photoFile = null;
            try {

                photoFile = createPhotoFile();
            } catch (IOException e) {
                Log.v("error occurred", e.getMessage());
            }
            if (photoFile != null) {
                photoUri = FileProvider.getUriForFile(MainActivity.this, getString(R.string.file_provider_authority), photoFile);
                takePic.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
                startActivityForResult(takePic, 1);
            }
        }
    }

    private File createPhotoFile() throws IOException {
        String name = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        imageFileName = "JPEG_" + name + "_";
        File storageDir = getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        image = File.createTempFile(imageFileName, ".jpg", storageDir);
        currentPhotoPath = image.getAbsolutePath();
        return image;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1 && resultCode == RESULT_OK) {
            Bitmap bitmap = BitmapFactory.decodeFile(currentPhotoPath);
            imageView.setImageBitmap(bitmap);
            imageView.setBackgroundColor(0);
        } else if (resultCode == RESULT_CANCELED) {
            Toast.makeText(this, "Cancelled", Toast.LENGTH_SHORT).show();
        }
    }

如果您建议我可以添加一些代码来解决该问题,那就太好了。

Screenshot of the problem which I am facing

0 个答案:

没有答案