【问题标题】:How to send user filled form to a particular mail id?如何将用户填写的表单发送到特定的邮件 ID?
【发布时间】:2014-07-19 18:42:37
【问题描述】:

如何从 multiselectionspinner 中读取值并将其显示在 EXTRA_TEXT 而不是“邮件正文”中?这是代码:请帮助我............

     public class MainActivity extends Activity {

  MultiSelectionSpinner spinner;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final String[] array = { "one", "two", "three", "a","b","c","d","e","f","g","h","i","f","g","h","i","j"};  
      spinner = (MultiSelectionSpinner) findViewById(R.id.spinner1);  
      spinner.setItems(array); 
      final EditText  textTo = (EditText) findViewById(R.id.editText1);
      final EditText  textSubject = (EditText) findViewById(R.id.editText2);
      final EditText  textMessage = (EditText) findViewById(R.id.editText3);
      final EditText  textadd = (EditText) findViewById(R.id.editText4);
      Button  buttonSend = (Button) findViewById(R.id.button1);


        buttonSend.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                String to = textTo.getText().toString();
                String subject = textSubject.getText().toString();
                String message = textMessage.getText().toString();
                String add = textadd.getText().toString();


                Intent i = new Intent(Intent.ACTION_SEND);
                i.setType("message/rfc822");
                i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
                i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
                i.putExtra(Intent.EXTRA_TEXT   , "body of mail");

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




}

        });

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

【问题讨论】:

    标签: android email android-intent


    【解决方案1】:
                    String to = textTo.getText().toString();
                    String subject = textSubject.getText().toString();
                    String message = textMessage.getText().toString();
                    String add = textadd.getText().toString();
    
                    Intent i = new Intent(Intent.ACTION_SEND);
                    i.setType("message/rfc822");
                    i.putExtra(Intent.EXTRA_EMAIL  , new String[]{to});
                    i.putExtra(Intent.EXTRA_SUBJECT, subject);
                    i.putExtra(Intent.EXTRA_TEXT   , message);
    

    不确定您想要“添加”字符串的位置,请详细说明。

    编辑 - 回应您的评论。使用 + 号将字符串“连接”在一起。

                    String to = textTo.getText().toString();
                    String subject = textSubject.getText().toString();
                    String message = textMessage.getText().toString();
                    String add = textadd.getText().toString();
    
                    Intent i = new Intent(Intent.ACTION_SEND);
                    i.setType("message/rfc822");
                    i.putExtra(Intent.EXTRA_EMAIL  , new String[]{to});
                    i.putExtra(Intent.EXTRA_SUBJECT, subject);
                    i.putExtra(Intent.EXTRA_TEXT   , to + subject + message + add);
    

    【讨论】:

    • 我希望所有四个都用于“邮件正文”。
    • 你知道如何从微调器中读取数据并与其他四个一起显示吗?我已经编辑了代码@Eran
    猜你喜欢
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-25
    • 2023-03-21
    • 1970-01-01
    相关资源
    最近更新 更多