发送图像作为附件

时间:2018-12-06 06:44:05

标签: android email android-intent android-image

我正在创建一个应用程序,我想将捕获的图像作为附件发送 给邮件发送邮件,但无法达到上述要求。任何人都可以指导我。

 emailsend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Log.i("Send email", "");
            String[] TO = {""};
            String[] CC = {""};
            Intent emailIntent = new Intent(Intent.ACTION_SEND);

            emailIntent.setData(Uri.parse("mailto:"));
            emailIntent.setType("application/image");
            emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
            emailIntent.putExtra(Intent.EXTRA_CC, CC);
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
            emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here");
            emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(pic));
            try {
                startActivity(Intent.createChooser(emailIntent, "Send mail..."));
                finish();
                Log.i("Finished sending", "");
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(clickimages.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
            }
        }
    });'

1 个答案:

答案 0 :(得分:0)

要将图像添加到您要发送的电子邮件中,可以执行以下操作:

Uri uri = Uri.parse("file://" + filepath);
intent(Intent.EXTRA_STREAM, uri);

发送邮件的目的是什么,在filepath变量中找到图像的路径。