我有一個簡單的聯繫表格應用程序,我想完成的是一旦表格填寫完畢,我想要的信息發送按鈕後直接發送到我的gmail。我不想讓「完成操作」彈出。只是直接發送到我的Gmail。我目前正在使用意圖使信息被髮送。有沒有其他類型的方法可以用來將信息直接發送到我的Gmail?如何通過按發送按鈕在android中輸出提交的信息?
這裏是我的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[]{"[email protected]"});
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);
}
}
//}
看到這個http://stackoverflow.com/questions/46663/how-to-send-an-email-by-java-application-using -gmail-yahoo-hotmail –
正如@madlymad所說的,要麼使用JavaMail API直接發送消息,要麼讓Android處理請求。與'startActivity(Intent.createChooser(emailIntent,「選擇一個電子郵件客戶端:」));'小信箱會彈出,你可以選擇你想要使用哪個電子郵件客戶端。您不應該假設您的手機上有哪些電子郵件客戶端,也不應該爲用戶做出選擇......至少這是它背後的想法。所以你需要盒子。 – GameDroids
謝謝,我會試一試 – OliverTwist