我想将捕获的图像作为附件发送到我的邮件中

拉莎·阿罕默德(Rasha Ahamed)

从图库发送电子邮件的问题运行正常,但捕获的图像无法正常工作。我尝试了不同的代码,其中一些在这里被评论。或者只是解释并教我它是如何工作的。

该应用程序从用户那里获取日期,然后使用电子邮件将其发送到预定义的电子邮件地址,但是问题是图像可以通过两种方式附加:一种是从已经捕获的图库中获取图像,另一种是通过用户捕获图像,然后将其上传,然后将其作为附件发送到电子邮件。

这是我应用程序中的第二个活动

package com.example.medipostrx;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class secondpage extends Activity{
    ImageView viewImage;
    File pic;
    Button b;
    Button c;

    String usernames;
    String clnumber;
    String clname;
    String spnnr;
    Uri imgui = null;
    int h = 0;


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.secondpage);
        Bundle data = getIntent().getExtras();
         usernames = data.getString("user");
         clnumber=data.getString("clnu");
         clname=data.getString("clnam");
         spnnr = data.getString("spn");
        b=(Button)findViewById(R.id.btntake);
c= (Button) findViewById(R.id.btnsub);
final ImageView y = (ImageView) findViewById(R.id.viewImage);
c.setOnClickListener(new View.OnClickListener() {

    @Override

    public void onClick(View v) {

        Intent i = new Intent(Intent.ACTION_SEND);
        //i.setType("message/rfc822");
        i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"[email protected]"});
        //i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"[email protected]"});
        i.putExtra(Intent.EXTRA_SUBJECT, "Clinic Number: " + clnumber );
        i.putExtra(Intent.EXTRA_TEXT   , "Username: " + usernames + "\nClinic Number: " + clnumber + "\nClinic Name: " + clname + "\nBranch: " + spnnr);

        //if(h==1){
        if(imgui != null){
            i.putExtra(Intent.EXTRA_STREAM, imgui);
            i.setType("image/png");
        }else{
            i.setType("plain/text");
        }
        //}//else{
            /*Drawable d =y.getBackground();
            BitmapDrawable bitDw = ((BitmapDrawable) d);
            Bitmap bitmap = bitDw.getBitmap();
            File  mFile = savebitmap(bitmap);
            Uri u = null;
               u = Uri.fromFile(mFile);
               i.putExtra(Intent.EXTRA_STREAM, u);
               i.setType("image/png");*/
            //i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(pic));
            //i.setType("image/png");
             //Toast.makeText(secondpage.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();

        //}
        try {
            startActivity(Intent.createChooser(i, "Send mail..."));
        } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(secondpage.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
        }

    }

});
        viewImage=(ImageView)findViewById(R.id.viewImage);

        b.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {

                selectImage();

            }

        });

    }
    private File savebitmap(Bitmap bmp) {
          String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
          OutputStream outStream = null;
         // String temp = null;
        File file = new File(extStorageDirectory, "temp.png");
          if (file.exists()) {
           file.delete();
           file = new File(extStorageDirectory, "temp.png");

          }

          try {
           outStream = new FileOutputStream(file);
           bmp.compress(Bitmap.CompressFormat.PNG, 100, outStream);
           outStream.flush();
           outStream.close();

          } catch (Exception e) {
           e.printStackTrace();
           return null;
          }
          return file;
         }


    @Override

    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds options to the action bar if it is present.

        getMenuInflater().inflate(R.menu.main, menu);

        return true;

    }



      private void selectImage() {



        final CharSequence[] options = { "Take Photo", "Choose from Gallery","Cancel" };



        AlertDialog.Builder builder = new AlertDialog.Builder(secondpage.this);

        builder.setTitle("Add Photo!");

        builder.setItems(options, new DialogInterface.OnClickListener() {

            @Override

            public void onClick(DialogInterface dialog, int item) {

                if (options[item].equals("Take Photo"))

                {

                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

                    File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg");

                    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));

                    startActivityForResult(intent, 1);


                }

                else if (options[item].equals("Choose from Gallery"))

                {

                    Intent intent = new   Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

                    startActivityForResult(intent, 2);



                }

                else if (options[item].equals("Cancel")) {

                    dialog.dismiss();

                }

            }

        });

        builder.show();

    }



    @Override

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == RESULT_OK) {

            if (requestCode == 1) {
                h=1;
                File f = new File(Environment.getExternalStorageDirectory().toString());

                for (File temp : f.listFiles()) {

                    if (temp.getName().equals("temp.jpg")) {

                        f = temp;
                        File photo = new File(Environment.getExternalStorageDirectory(), "temp.jpg");

                        break;

                    }

                }

                try {

                    Bitmap bitmap;

                    BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();



                    bitmap = BitmapFactory.decodeFile(f.getAbsolutePath(),

                            bitmapOptions); 



                    viewImage.setImageBitmap(bitmap);




                    String path = android.os.Environment

                            .getExternalStorageDirectory()

                            + File.separator

                            + "Phoenix" + File.separator + "default";

                    f.delete();

                    OutputStream outFile = null;

                    File file = new File(path, String.valueOf(System.currentTimeMillis()) + ".jpg");

                    try {

                        outFile = new FileOutputStream(file);

                        bitmap.compress(Bitmap.CompressFormat.JPEG, 85, outFile);
//pic=file;
                        outFile.flush();

                        outFile.close();


                    } catch (FileNotFoundException e) {

                        e.printStackTrace();

                    } catch (IOException e) {

                        e.printStackTrace();

                    } catch (Exception e) {

                        e.printStackTrace();

                    }

                } catch (Exception e) {

                    e.printStackTrace();

                }

            } else if (requestCode == 2) {



                Uri selectedImage = data.getData();
imgui = selectedImage;
                String[] filePath = { MediaStore.Images.Media.DATA };

                Cursor c = getContentResolver().query(selectedImage,filePath, null, null, null);

                c.moveToFirst();

                int columnIndex = c.getColumnIndex(filePath[0]);

                String picturePath = c.getString(columnIndex);

                c.close();

                Bitmap thumbnail = (BitmapFactory.decodeFile(picturePath));

                Log.w("path of image from gallery......******************.........", picturePath+"");

                viewImage.setImageBitmap(thumbnail);

            }

        }

    }   


}`

我的xml文件是;

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="@string/filenumber" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/btntake"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/takepicutre" />
        <ImageView

            android:id="@+id/viewImage"

            android:layout_width="200dp"

            android:layout_height="200dp"
            android:layout_gravity="center"

            android:src="@drawable/cameraa" />

        <Button
            android:id="@+id/btnsub"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/email" />

</LinearLayout>
自动机器人
Intent iShare;
iShare = new Intent(Intent.ACTION_SEND);
iShare.setType("image/png");
iShare.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+fn.getPath()));
iShare.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(new StringBuilder()
        .append("<p><b>Path</b></p>").append("<small><p>"+sb+"</p></small>").toString()));
startActivity(Intent.createChooser(iShare, "Share"));

AFAIK,您必须将捕获的图像作为附件发送到电子邮件中,然后可以尝试上面的代码。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

我想将过滤后的数据从数据库发送到我的邮件中

来自分类Dev

Phonegap:捕获图像,视频并作为附件发送到电子邮件中

来自分类Dev

我想将文件作为附件发送到API POST请求

来自分类Dev

我想将图像 URL 作为 json 数据上传到我的角度表单并将其发送到服务器。图像 URL 来自服务器响应

来自分类Dev

在Servlet中获取一组图像并将其发送到我的Android应用

来自分类Dev

在Servlet中获取一组图像并将其发送到我的Android应用

来自分类Dev

PHP邮件未将电子邮件发送到我的电子邮件地址

来自分类Dev

使用sendgrid如何知道我的电子邮件是退回还是成功发送到我的代码中

来自分类Dev

我试图直接将值作为参数发送到我的数组中,但是它不起作用

来自分类Dev

我想将 window.prompt 中的数据发送到我的服务器,但可能缺少某些内容 (javascript+php)

来自分类Dev

无法获取我的表单数据以发送到我的电子邮件

来自分类Dev

PHP电子邮件不会发送到我的电子邮件

来自分类Dev

iOS:自定义键盘:我想将图像发送到textDocumentProxy(输入控件)

来自分类Dev

我如何从NSMutableArray获取图像并将其发送到我的collectionView

来自分类Dev

我想将数据从Lua发送到C#

来自分类Dev

我想将数据发送到本地服务器

来自分类Dev

mail()函数不会将信息发送到我的电子邮件

来自分类Dev

如何将控制台输出发送到我的电子邮件?

来自分类Dev

如何将nagios警报通过电子邮件发送到我的gmail?

来自分类Dev

我想将控制器中的变量发送到 Laravel 上的 Trait

来自分类Dev

我的ajax POST未发送到我的servlet

来自分类Dev

如何将多个参数作为单个实体从jquery发送到我的Controller?

来自分类Dev

将图像发送到我的C#应用程序

来自分类Dev

不会将我的值从按钮和文本发送到我的js文件中

来自分类Dev

如何通过我的应用程序在soundcloud中上传音频,我也想将该ID发送到我的服务器

来自分类Dev

我如何打印/回显stdClass对象中包含的数组键和值并将这些值发送到我的邮件?

来自分类Dev

如何在单个消息中将多个电子邮件结果发送到我的电子邮件

来自分类Dev

我想将请求从UE4 c ++游戏发送到我的php脚本,以便它与mysql数据库进行交互

来自分类Dev

将数据发送到我的母版页

Related 相关文章

  1. 1

    我想将过滤后的数据从数据库发送到我的邮件中

  2. 2

    Phonegap:捕获图像,视频并作为附件发送到电子邮件中

  3. 3

    我想将文件作为附件发送到API POST请求

  4. 4

    我想将图像 URL 作为 json 数据上传到我的角度表单并将其发送到服务器。图像 URL 来自服务器响应

  5. 5

    在Servlet中获取一组图像并将其发送到我的Android应用

  6. 6

    在Servlet中获取一组图像并将其发送到我的Android应用

  7. 7

    PHP邮件未将电子邮件发送到我的电子邮件地址

  8. 8

    使用sendgrid如何知道我的电子邮件是退回还是成功发送到我的代码中

  9. 9

    我试图直接将值作为参数发送到我的数组中,但是它不起作用

  10. 10

    我想将 window.prompt 中的数据发送到我的服务器,但可能缺少某些内容 (javascript+php)

  11. 11

    无法获取我的表单数据以发送到我的电子邮件

  12. 12

    PHP电子邮件不会发送到我的电子邮件

  13. 13

    iOS:自定义键盘:我想将图像发送到textDocumentProxy(输入控件)

  14. 14

    我如何从NSMutableArray获取图像并将其发送到我的collectionView

  15. 15

    我想将数据从Lua发送到C#

  16. 16

    我想将数据发送到本地服务器

  17. 17

    mail()函数不会将信息发送到我的电子邮件

  18. 18

    如何将控制台输出发送到我的电子邮件?

  19. 19

    如何将nagios警报通过电子邮件发送到我的gmail?

  20. 20

    我想将控制器中的变量发送到 Laravel 上的 Trait

  21. 21

    我的ajax POST未发送到我的servlet

  22. 22

    如何将多个参数作为单个实体从jquery发送到我的Controller?

  23. 23

    将图像发送到我的C#应用程序

  24. 24

    不会将我的值从按钮和文本发送到我的js文件中

  25. 25

    如何通过我的应用程序在soundcloud中上传音频,我也想将该ID发送到我的服务器

  26. 26

    我如何打印/回显stdClass对象中包含的数组键和值并将这些值发送到我的邮件?

  27. 27

    如何在单个消息中将多个电子邮件结果发送到我的电子邮件

  28. 28

    我想将请求从UE4 c ++游戏发送到我的php脚本,以便它与mysql数据库进行交互

  29. 29

    将数据发送到我的母版页

热门标签

归档