I am trying to create an activity to send an email. I am using an Intent Object "Action send" to launch the email client.
However is not detecting the email client, this is the first time I am doing this, please help. What is wrong with my code?
public class email extends Activity {
private Button send;
DBHelper mydb1;
private ListView obj;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mydb1 = new DBHelper(this);
setContentView(R.layout.email_display);
ArrayList array_list = mydb1.getAllCotacts();
ArrayAdapter arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, array_list);
obj = (ListView) findViewById(R.id.listView2);
obj.setAdapter(arrayAdapter);
send =(Button) findViewById(R.id.send_button);
send.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
try {
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"myemail@gmail.com"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "HEY");
emailIntent.putExtra(Intent.EXTRA_CC, "example@gmail.com");
emailIntent.setType("message/rfc822");
startActivity(emailIntent);
} catch (ActivityNotFoundException anfe) {
Toast toast = Toast.makeText(email.this, "Sorry, no email client found", Toast.LENGTH_LONG);
toast.show();
}
}
}
);
}
}