Snippet

The following snippet shows how to send Email via an Email Intent in an Android Activity.

  1. package com.livrona.apps.radio.activity;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.widget.ImageButton;
  8.  
  9. import com.livrona.andriod.commons.utils.Log;
  10.  
  11. public class AboutScreen extends Activity {
  12.  
  13.  @Override
  14.  public void onCreate(Bundle savedInstanceState) {
  15.  
  16.    Log.d("in : onCreate(..)");
  17.    super.onCreate(savedInstanceState);
  18.   setContentView(R.layout.about_screen);
  19.  
  20.    // find it          
  21.   ImageButton buttonEmail=(ImageButton)findViewById(R.id.button_email);
  22.        
  23.   buttonEmail.setOnClickListener(new View.OnClickListener() {
  24.     public void onClick(View view) {
  25.       Log.d("in : Button Email onClick(..)");
  26.  
  27.        // Intent
  28.       Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
  29.  
  30.        // define TO email
  31.       String aEmailList[] = { "to@email.com"};
  32.       emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
  33.  
  34.       emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Your Subject");
  35.  
  36.        emailIntent.setType("text/html");
  37.        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Email Body");
  38.  
  39.        // support multiple email clients
  40.       startActivity(Intent.createChooser(emailIntent, "Send your email via:"));
  41.       } // onclick
  42.    }); // listener
  43.  } // method
  44.  
  45. } // class

<!>