【发布时间】: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