English 中文(简体)
Android:如何从申请中将图像作为电子邮件发送?
原标题:Android: How to send an image as email attachment from application?

我目前正在试图制作一个能够反映情况的照片,然后把照片放在一个电子邮件上,该电子邮件将事先确定。

我有电子邮件工作,我有照相机工作。 我似乎无法了解照相机作为附件加的照片。 我的图像像像像像是一种预科,如果是这样,我就没有任何问题。

当发出电子邮件时,就会发现一个照片,但腐败,没有。 就像我制造一种不存在的情况一样。 我认为,这只是把所拍摄的画面与创建附属部分混为一谈,但我没有任何想法! 如果有人能帮助我,我会非常感激!

Here is my MainActivity where the email is being created along with the camera:

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore.Images;
import android.provider.MediaStore.Images.Media;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

public class EmailActivity extends Activity {
        Button send;
        EditText address, subject, emailtext;
        protected static final int CAMERA_PIC_REQUEST = 0;



    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.email);
        send=(Button) findViewById(R.id.emailsendbutton);
        address=(EditText) findViewById(R.id.emailaddress);
        subject=(EditText) findViewById(R.id.emailsubject);
        emailtext=(EditText) findViewById(R.id.emailtext);

        send.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                                // TODO Auto-generated method stub

                            if
                            (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
                            {

                            }

                            File pngDir = new File(

                                    Environment.getExternalStorageDirectory(),
                                    "Android/data/com.phstudios.jbrefurb/quote");

                            if (!pngDir.exists())
                                pngDir.mkdirs();

                            File pngFile = new File(pngDir, "pic1.png");
                            Uri pngUri = Uri.fromFile(pngFile);


                                     Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

                                      emailIntent.setType("image/png");

                                      emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ "random@yahoo.co.uk"});

                                      emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText());

                                      emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext.getText());

                                      emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, pngUri);

                                      emailIntent.setType("image/png");


                                    EmailActivity.this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));

     }
            });

 Button camera = (Button) findViewById(R.id.button2); 
        camera.setOnClickListener(new View.OnClickListener() { 
            public void onClick(View view) {
                Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                  startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);  
;

                }     
            });  
        }  

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {         
        if (requestCode== 0 && resultCode == Activity.RESULT_OK){                 
            Bitmap x = (Bitmap) data.getExtras().get("data");                 
            ((ImageView)findViewById(R.id.imageView1)).setImageBitmap(x);                 
            ContentValues values = new ContentValues();

            values.put(Images.Media.TITLE, "title");         
            values.put(Images.Media.BUCKET_ID, "test");         
            values.put(Images.Media.DESCRIPTION, "test Image taken");         
            values.put(Images.Media.MIME_TYPE, "image/png");         
            Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);         
            OutputStream outstream;                 
            try {                         
                outstream = getContentResolver().openOutputStream(uri);          
                x.compress(Bitmap.CompressFormat.JPEG, 70, outstream);         
                outstream.close();                 
                } catch (FileNotFoundException e) {                         
                    //                 
                    }catch (IOException e){                         
                        //                 
                        }         
            } }   
    } 

我只想简单一点,我不要把他们联系在一起。

最佳回答
public class MainActivity extends Activity {
  Button send;
  Bitmap thumbnail;
  File pic;
  EditText address, subject, emailtext;
  protected static final int CAMERA_PIC_REQUEST = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    send=(Button) findViewById(R.id.emailsendbutton);
    address=(EditText) findViewById(R.id.emailaddress);
    subject=(EditText) findViewById(R.id.emailsubject);
    emailtext=(EditText) findViewById(R.id.emailtext);
    Button camera = (Button) findViewById(R.id.button1); 
    camera.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0){
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);  
        }
        });
        send.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0){
            Intent i = new Intent(Intent.ACTION_SEND);
            i.putExtra(Intent.EXTRA_EMAIL, new String[]{"fake@fake.edu"});
            i.putExtra(Intent.EXTRA_SUBJECT,"On The Job");
            //Log.d("URI@!@#!#!@##!", Uri.fromFile(pic).toString() + "   " + pic.exists());
            i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(pic));
            i.setType("image/png");
            startActivity(Intent.createChooser(i,"Share you on the jobing"));
        }
        });       
    
}     
protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (requestCode == CAMERA_PIC_REQUEST) {  
     thumbnail = (Bitmap) data.getExtras().get("data");  
    ImageView image = (ImageView) findViewById(R.id.imageView1);  
    image.setImageBitmap(thumbnail);
        try {
            File root = Environment.getExternalStorageDirectory();
            if (root.canWrite()){
                 pic = new File(root, "pic.png");
                FileOutputStream out = new FileOutputStream(pic);
                thumbnail.compress(CompressFormat.PNG, 100, out);
                out.flush();
                out.close();
            }
        } catch (IOException e) {
            Log.e("BROKEN", "Could not write file " + e.getMessage());
        }   
   
    }  
} 
问题回答

审判

        Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("text/plain");
    i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"123@gmail.com"});
    i.putExtra(Intent.EXTRA_SUBJECT, " report");
    i.putExtra(Intent.EXTRA_TEXT   , "PFA");
    i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(destinationFile));//pngFile 

        startActivity(Intent.createChooser(i, "Send mail..."));

审判

        send.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View arg0) {
                Intent i = new Intent(Intent.ACTION_SEND);
                i.putExtra(Intent.EXTRA_EMAIL, new String[]{"fake@fake.edu"});
                i.putExtra(Intent.EXTRA_SUBJECT, "On The Job");
                //Log.d("URI@!@#!#!@##!", Uri.fromFile(pic).toString() + "   " + pic.exists());
                if(pic != null)
                {  i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(pic));}

                i.setType("image/png");
                i.setType("message/rfc822");

                startActivity(Intent.createChooser(i, "Share you on the jobing"));

            }
        });
    }




相关问题
Angle brackets in php

I want to store angle brackets in a string in PHP because i want to eventually use mail() to send an HTML email out. The following is the code that doesn t seem to work. while(...) { $msg .= "<...

authlogic auto_register feature using my options

I have auto registration working with authlogic using gaizka s version of authlogic_openid which I found on Github since pelle s original addition of the feature seemed to cause issues. http://...

Zend 邮件问题,涉及外国char子+ com子

泽斯德邮局在名称被定为具有外国性质(如“保”)和 com(”)的物品时,就放弃了一种例外(因为邮局(邮局)退回假)。 重新提出以下守则。

How to track an email in Java?

How I can track an email? I m using java on the server side for sending emails. I want to track whether it is delivered , opened, etc... How I can do that ?

Web Link in a mail is not rendering as link in yahoo

string from = "abc@gmail.com"; string to = "xyz@gmail.com,xyz@yahoo.co.in"; string password="abcxyz"; MailMessage mail = new System.Net.Mail.MailMessage(); mail.To.Add(to); mail.From = new ...

SharePoint - Approaching Website Storage Limit Email

How can i go about changing the distribution list as well as the email text for the email that goes out to site collection admin when a site collection approaches it s size limit? Thanks for your ...

How to create an email mailing list

Im creating a coming soon page for a website im developing, and im adding an option for the user to enter their email address so we can email them when the site is up. How do I do this?

CCNet email does not include MSBuild results

We re using CCNet 1.4.4.83 but when an MSBuild task fails, we don t get the MSBuild results (i.e. missing file or whatever reason the compile failed) in the email notification. I do see the build ...

热门标签