thieumao

Mail Android

Jan 11th, 2017
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1. import android.content.Intent;
  2. import android.net.Uri;
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.Button;
  7.  
  8. public class MainActivity extends AppCompatActivity {
  9.     private Button send_email;
  10.     private Button mail_box;
  11.     @Override
  12.     protected void onCreate(Bundle savedInstanceState) {
  13.         super.onCreate(savedInstanceState);
  14.         setContentView(R.layout.activity_main);
  15.         sendEmails();
  16.         openEmailInBox();
  17.     }
  18.  
  19.     //Compose an email
  20.     public void sendEmails(){
  21.         send_email = (Button)findViewById(R.id.button);
  22.         send_email.setOnClickListener(
  23.                 new View.OnClickListener() {
  24.                     @Override
  25.                     public void onClick(View v) {
  26.                         String[] TO = {""};
  27.                         String[] CC = {""};
  28.                         Intent emailIntent = new Intent(Intent.ACTION_SEND);
  29.  
  30.                         emailIntent.setData(Uri.parse("mailto:"));
  31.                         emailIntent.setType("text/plain");
  32.                         emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
  33.                         emailIntent.putExtra(Intent.EXTRA_CC, CC);
  34.                         emailIntent.putExtra(Intent.EXTRA_SUBJECT, "");
  35.                         emailIntent.putExtra(Intent.EXTRA_TEXT, "");
  36.                         startActivity(Intent.createChooser(emailIntent, "Send mail..."));
  37.                         finish();
  38.                     }
  39.                 }
  40.         );
  41.     }
  42.  
  43.     //mail list
  44.     public void openEmailInBox(){
  45.         mail_box =(Button)findViewById(R.id.button2);
  46.         mail_box.setOnClickListener(
  47.                 new View.OnClickListener() {
  48.                     @Override
  49.                     public void onClick(View v) {
  50.                         Intent mailBoxIntent = new Intent(Intent.ACTION_MAIN);
  51.                         mailBoxIntent.addCategory(Intent.CATEGORY_APP_EMAIL);
  52.                         startActivity(mailBoxIntent);
  53.                     }
  54.                 }
  55.         );
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment