It looks like you should just build a list with only one item. Something like:
...
List<String> toEmailList = new ArrayList<String>();
toEmailList.add("anything@gmail.com");
...
Pergunta
I am developing an application that has a form to send email without in-built application. I have seen so many examples for email sending. In all the examples, it is for so many email ID. That means we can send email to multiple persons at a time. But I want to send email to one person only. I am following this tutorial. Please let me know where and what should I have to change the code.
http://javapapers.com/android/android-email-app-with-gmail-smtp-using-javamail/
From this tutorial in the ToEmail box, we can add multiple email ID. But I want to add a single email ID only.Please help me where should I change this.This is the code I have edited from this tutorial..plzzz help.
import java.util.Arrays;
import java.util.List;
import javax.security.auth.Subject;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.text.Html;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class Contact extends Activity implements OnClickListener, OnItemSelectedListener
{
Button submit1,clear;
EditText et1,et2,et3;
Spinner spin;
String[] selction = { "I want to request a mobile feature",
"I want to tell about something that I like",
"I want to tell you about something that I do not like",
"I have general comments",
"I want to contact the office",
"I want to suggest an improvement in the church premise"};
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contact);
Spinner spin=(Spinner)findViewById(R.id.spinner1);
spin.setOnItemSelectedListener(this);
@SuppressWarnings({ "unchecked", "rawtypes" })
ArrayAdapter aa = new ArrayAdapter(this,android.R.layout.simple_spinner_item,selction);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//Setting the ArrayAdapter data on the Spinner
spin.setAdapter(aa);
//--------------------Submit_Button_Start-----------------------------------------------------------
final Button submit1=(Button)findViewById(R.id.button1);
submit1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Log.i("SendMailActivity", "Send Button Clicked.");
String fromEmail ="user@gmail.com";
String fromPassword="password";
String toEmails="anything@gmail.com";
//List<String> toEmailList = Arrays.asList(toEmails.split("\\s*,\\s*"));
//Log.i("SendMailActivity", "To List: " + toEmailList);
String emailBody = ((TextView) findViewById(R.id.editText1)).getText().toString();
new SendMailTask(Contact.this).execute(fromEmail,fromPassword, toEmails, emailBody);
}
});
//--------------------Submit_Button_End-----------------------------------------------------------
clear=(Button)findViewById(R.id.button2);
clear.setOnClickListener(this);
et1=(EditText)findViewById(R.id.editText1);
et2=(EditText)findViewById(R.id.editText2);
et3=(EditText)findViewById(R.id.editText3);
/*ArrayAdapter<CharSequence> adapter=ArrayAdapter.createFromResource(this,R.array.question,android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);*/
}
public boolean onCactivity_list_itemreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.contact, menu);
return true;
}
/*
@Override
public void onItemSelected(AdapterView<?> parent, View v, int position,long id) {
// TODO Auto-generated method stub
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
*/
@Override
public void onClick(View v1)
{
if(v1==clear)
{
et1.setText("");
et2.setText("");
et3.setText("");
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
/*
new AlertDialog.Builder(Contact1.this)
.setMessage("Your requested has been Accepted\nThank You")
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which)
{
dialog.cancel();
}
})
.show();*/
}
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
Solução
It looks like you should just build a list with only one item. Something like:
...
List<String> toEmailList = new ArrayList<String>();
toEmailList.add("anything@gmail.com");
...