【问题标题】:how to output submitted info in android by pressing the send button?如何通过按发送按钮在android中输出提交的信息?
【发布时间】:2013-12-14 14:51:59
【问题描述】:

我有一个简单的联系表格应用程序,我想要完成的是,一旦表格填写完毕,我希望在按下发送按钮后将信息直接发送到我的 gmail。我不希望弹出“使用完成的操作”。直接发到我的gmail。我目前正在使用意图发送信息。是否可以使用其他类型的方法将信息直接发送到我的 gmail?

这是我的 MainActivity.java 文件:

package com.qnutapps.contactform1;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity  extends Activity implements OnClickListener{
/** Called when the activity is first created. */

    EditText etname, etphone, etemail, etadd;

    Button send;

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

    etname = (EditText) findViewById (R.id.etName);

    etphone = (EditText) findViewById (R.id.etPhone);

    etemail = (EditText) findViewById (R.id.etEmail);       

    etadd = (EditText) findViewById (R.id.etAdd);

    send = (Button) findViewById (R.id.send);      

    send.setOnClickListener(this);
  }

public void onClick(View Arg0) {


         //if(etname.getText().toString().length()==0)  
         //{           
          //etname.setError( "Please Enter Your Name" );  
         //}  
         //else if(etphone.getText().toString().length()==0)  
         //{           
          //etphone.setError( "Please Enter Your Phone #" ); 
         //}
         //else if(etemail.getText().toString().length()==0)  
         //{           
          //etemail.setError( "Please Enter Your E-mail" );
         //}
         //else if(etadd.getText().toString().length()==0)  
         //{           
          //etadd.setError( "Vul uw bericht in" );  
         //}
         //else if(subject.getSelectedItemPosition()==0)  
         //{           
          //Toast.makeText(MainActivity.this,"Please select the Subject",Toast.LENGTH_SHORT).show(); 
         //}
         //else
         //{             
            Toast.makeText(getApplicationContext(), "Sending E-Mail", Toast.LENGTH_SHORT).show(); //Sends message after button is clicked

            StringBuilder body = new StringBuilder();

            body.append("Name: "+etname.getText().toString());

            body.append("\nPhone: "+etphone.getText().toString());

            body.append("\nEmail: "+etemail.getText().toString());

            body.append("\nAdditional Information: "+etadd.getText().toString());



            Intent emailIntent = new Intent(Intent.ACTION_SEND); 

            emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"marketing.otwist@gmail.com"});           

            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Customer Details");

            emailIntent.putExtra(Intent.EXTRA_TEXT, body.toString());

            emailIntent.setType("message/rfc822");  //can also use "message/rfc822"

            startActivity(emailIntent);  


         }         
}
//}

【问题讨论】:

  • 正如@madlymad 所说,您要么使用JavaMail API 直接发送消息,要么需要让Android 处理请求。使用startActivity(Intent.createChooser(emailIntent, "Choose an Email client :")); 会弹出小消息框,您可以在其中选择要使用的电子邮件客户端。您不应该对手机上可用的电子邮件客户端做出任何假设,也不应该尝试为用户做出选择……至少这是它背后的想法。所以你需要这个盒子。
  • 谢谢,我试试看
  • @GameDroids 谢谢。这不像我试图为用户做出选择。我想要的只是用户填写表格并按下发送按钮然后砰!直接到我的邮箱。我只是一个初学者,所以我还在努力理解这种新的疯狂语言

标签: android eclipse android-intent


【解决方案1】:

您可以使用 JavaMail API,但它并不那么容易。

检查答案:Sending Email in Android using JavaMail API without using the default/built-in app

【讨论】:

  • 是的,我知道这并不容易,我只是一个初学者。我会试一试。谢谢
  • 您可以尝试使用 post to google 电子表格而不是电子邮件。喜欢这里的这个人:stackoverflow.com/questions/6174962/…
【解决方案2】:

使用 HTML 你可以很容易地发送它。 mailto : "电子邮件地址"。

我不知道你是否可以在这里使用 HTML

【讨论】:

  • 不幸的是我意识到这并不容易哈哈
猜你喜欢
  • 2023-03-23
  • 1970-01-01
  • 2012-06-07
  • 2017-01-07
  • 2017-10-31
  • 2014-08-07
  • 2017-12-28
  • 2016-05-01
  • 2021-10-09
相关资源
最近更新 更多