English 中文(简体)
仅通过电子邮件传送1个图像
原标题:Android Send only 1 image via email in app

我在我的肩上创建了一个“信用”网页,并认为你可以选择向已经预先确定的电子邮件地址发送照片。 我面临的问题是,它从电话袋里拿到所有图像,并在电子邮件中发送。 我所要做的是一次情况。 我似乎必须努力找出能够仅仅传播一个形象的变化。 是否有任何人可以帮助?

我的守则是:

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.random.jbrefurb/quote");

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

                            Uri pngUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;


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


                                      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/jpeg");


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


                        }
                });

        Button back = (Button) findViewById(R.id.button1); 
        back.setOnClickListener(new View.OnClickListener() { 
            public void onClick(View view) {
                 // fire intent
                finish(); // finish current activity
                Intent austinIntent = new Intent(view.getContext(), 
                        ContactActivity.class); 
                startActivityForResult(austinIntent, 0);


            } 


        });




        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/jpeg");         
            Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);         
            OutputStream outstream;                 
            try {                         
                outstream = getContentResolver().openOutputStream(uri);          
                x.compress(Bitmap.CompressFormat.JPEG, 100, outstream);         
                outstream.close();                 
                } catch (FileNotFoundException e) {                         
                    //                 
                    }catch (IOException e){                         
                        //                 
                        }         
            } }   
    } 

许多预告

问题回答

如果需要帮助,则在我的申请过程中使用该守则。

 private OnClickListener shareemail=new OnClickListener(){
        @Override
        public void onClick(View v) {


            String address = "your emailaddress";
        File filee;
       if(address.length()==0)  
       {
           AlertDialog.Builder ab=new AlertDialog.Builder(null);
            ab.setMessage("Email Address must not be empty!");
            ab.setPositiveButton("OK", new DialogInterface.OnClickListener(){
               @Override 
               public void onClick(DialogInterface dialog, int which) {

               }
            });
            ab.show();
       }
       else
       {

          ArrayList<Uri> uris = new ArrayList<Uri>();
         Uri u;
         Intent emailSession = new Intent(Intent.ACTION_SEND_MULTIPLE);
         emailSession.putExtra(Intent.EXTRA_SUBJECT,"your subject");
         emailSession.setType("images/*");
         emailSession.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {address});
         emailSession.putExtra(android.content.Intent.EXTRA_TEXT,"body text");
        FileWriter fw;
        BufferedWriter bw;
        try{

              filee = new File(path of image you want to send);
              if(filee.exists())
              {

                Uri u1 = Uri.fromFile(filee);
                uris.add(u1);
                emailSession.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);

             startActivity(emailSession);
            }
        }
            catch (ActivityNotFoundException e)
            {
                Toast.makeText(getBaseContext(),  e.getMessage(), Toast.LENGTH_SHORT).show();
            }
    }}
    };




相关问题
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 ...

热门标签