-3

我已经尝试过了...但是当我提交表单时,它会发送到撰写邮件...我只想通过单击提交按钮来发送邮件...请帮助我...

Intent mailintent = new Intent(android.content.Intent.ACTION_SEND);
mailintent.setType("text/plain");
mailintent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]        
         {"amitk.123@gmail.com" , "ankush.123@gmail.com"});
mailintent.putExtra(android.content.Intent.EXTRA_SUBJECT, "info...");         
startActivity(mailintent);

<uses-permission android:name="android.permission.INTERNET" /> 

在清单文件中。

4

2 回答 2

1

我认为您正在尝试以编程方式发送电子邮件,而无需打开电子邮件编辑器。

如果是这样,您可以检查此链接

希望这可以帮助

于 2012-05-31T11:21:39.667 回答
-1
package com.contact;
import java.util.regex.Pattern;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

public class ContactusActivity extends Activity {
    // Initializing variables
    EditText inputName;
    EditText inputEmail;
    EditText inputphone;
    EditText inputcomment;
    ImageView iv;

    public final Pattern EMAIL_ADDRESS_PATTERN = Pattern.compile(
            "[a-zA-Z0-9+._%-+]{1,256}" +
            "@" +
            "[a-zA-Z0-9][a-zA-Z0-9-]{0,64}" +
            "(" +
            "." +
            "[a-zA-Z0-9][a-zA-Z0-9-]{0,25}" +
            ")+"
        );
    String regexStr = "^[0-9]$";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        inputName = (EditText) findViewById(R.id.name);
        inputEmail = (EditText) findViewById(R.id.email);
        inputphone = (EditText) findViewById(R.id.phone);
        inputcomment = (EditText) findViewById(R.id.comment);
        Button sendmail = (Button) findViewById(R.id.sendmail);
        final ImageView iv= (ImageView) findViewById(R.id.test_image);
        iv.setBackgroundResource(R.animator.animation);

        sendmail.setOnClickListener(new View.OnClickListener() {

            public void onClick(View arg0) {



                String strname=inputName.getText().toString();
                String strmail=inputEmail.getText().toString();
                String strphone=inputphone.getText().toString();
                String strcmnt=inputcomment.getText().toString();


                if(strname.length() == 0  || strmail.length() == 0 
                         || strphone.length() == 0 || strcmnt.length() == 0 )   
                {


                Dialog d=new Dialog(ContactusActivity.this);
                d.setContentView(R.layout.dialog);
                d.setTitle("");
                d.show();
                    //Toast toast=Toast.makeText(ContactusActivity.this, "please fill all the details.....", 7000);
                    //toast.setGravity(Gravity.CENTER,0,0);
                      //  toast.show();

                }
                 else

                     if(strcmnt.length() <=20) {
                         Dialog d=new Dialog(ContactusActivity.this);
                            d.setContentView(R.layout.comment);
                            d.setTitle("");
                            d.show();


                        }
                     else

                         if(strname.length() <=3) {
                             Dialog d=new Dialog(ContactusActivity.this);
                                d.setContentView(R.layout.name);
                                d.setTitle("");
                                d.show();

                         }
                     else

                         if(strphone.length() <10 || strphone.length() >10) {
                             Dialog d=new Dialog(ContactusActivity.this);
                                d.setContentView(R.layout.phone);
                                d.setTitle("");
                                d.show();


                            }


                     else{


                        if(checkEmail(strmail)){ 





                 String result=strname +"\n"+ strmail+"\n" + strphone+"\n" + strcmnt;
                Intent mailintent = new Intent(android.content.Intent.ACTION_SEND);
               mailintent.setType("text/plain");
                mailintent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] {"amitk.cql@gmail.com" , "ankush.cql@gmail.com"});
                mailintent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Please collect my info...");

                mailintent.putExtra(android.content.Intent.EXTRA_TEXT, result ); 

                startActivity(Intent.createChooser(mailintent, "Sending mail..."));
                inputName.setText("");
                inputEmail.setText("");
                inputphone.setText("");
                inputcomment.setText("");

                         }
                         else
                        {
                             Dialog d=new Dialog(ContactusActivity.this);
                            d.setContentView(R.layout.email);
                            d.setTitle("");
                            d.show();

                        }

                        }
            }

             });
       //  iv.setOnClickListener(new OnClickListener(){

        //  public void onClick(View v) {

                AnimationDrawable anim= (AnimationDrawable)  iv.getBackground();
                anim. start();
            }

       // });

   // }


    private boolean checkEmail(String strmail) {
        return EMAIL_ADDRESS_PATTERN.matcher(strmail).matches();

}


}
于 2012-05-31T12:13:49.703 回答