我有一个简单的联系表单应用程序,我想要完成的是表单填写后,我希望在按下发送按钮后直接将信息发送到我的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);
}
}
//}
答案 0 :(得分:0)
您可以使用JavaMail API但不是那么容易。
检查答案:Sending Email in Android using JavaMail API without using the default/built-in app
答案 1 :(得分:0)
使用HTML,你可以很容易地发送它。 mailto:“电子邮件地址”。
我不知道你可以在这里使用HTML吗
答案 2 :(得分:0)
搜索Android Intents并了解如何使用它们。这是一篇可以帮助您入门的帖子: