How to send email from your application
Today we'll create an easy email sender application.
First of all we need to create a layout to set the address, the subject and email body box.
- <?xml version="1.0" encoding="utf-8"?><LinearLayout android:id="@
- +id/LinearLayout01" android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- xmlns:android="http://schemas.android.c
om/apk/res/android" - android:orientation="vertical"><LinearLayout android:id="@+id/LinearLayout02"
; - android:layout_width="wrap_content" android:layout_height="wrap_content"
- android:orientation="horizontal"><EditText android:layout_width="wrap_content"
- android:layout_height="wrap_content" android:width="170dip" android:id="@
- +id/emailaddress"></EditText><TextView android:layout_width="wrap_content"
- android:layout_height="wrap_content" android:id="@+id/emailaddress"
- android:text="Email address"></TextView>
- </LinearLayout>
- <LinearLayout android:id="@+id/LinearLayout03"
; - android:layout_width="wrap_content" android:layout_height="wrap_content"
- android:orientation="horizontal"><EditText android:layout_width="wrap_content"
- android:layout_height="wrap_content" android:width="170dip" android:id="@
- +id/emailsubject"></EditText><TextView android:layout_width="wrap_content"
- android:layout_height="wrap_content" android:id="@+id/emailsubject"
- android:text="Subject"></TextView>
- </LinearLayout>
- <EditText android:layout_width="wrap_content"
- android:layout_height="wrap_content" android:lines="5" android:width="300dip"
- android:id="@+id/emailtext"></EditText>
- <Button android:layout_width="wrap_content" android:layout_height="wrap_content"
- android:id="@+id/emailsendbutton&quo
t; android:text="Send!" - android:width="150dip"></Button>
- </LinearLayout>
Ugly, but works...
Next we create a new class, called ....uhhhm...Email, then modify like this:
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListe
ner; - import android.widget.Button;
- import android.widget.EditText;
- public class Email extends Activity {
- Button send;
- EditText address, subject, emailtext;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.email);
- address=(EditText) findViewById(R.id.emailaddress);
- subject=(EditText) findViewById(R.id.emailsubject);
- emailtext=(EditText) findViewById(R.id.emailtext);
- send.setOnClickListener(new OnClickListener() {
- @Override
- // TODO Auto-generated method stub
- final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
- emailIntent.setType("plain/text");
- emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ address.getText().toString()});
- emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText());
- emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext.getText());
- Email.this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
- }
- });
- }
- }
It will use the button's onclicklistener method to send the email. It does not work on emulator, but works on real devices.
New tutorials from Helloandroid
Recent Apps
Android on Twitter
-
@Idevicegazette (iDevice Gazette)
GSM-to-Skype bridge lets you lose those roaming fees http://bit.ly/lbRJeh #android
11 years 13 weeks ago -
@tommy_banane (tom b.)
RT @AndroidFavorite: #Android New Desktop Android Market Is Live, Adds Several New Features http://zorr0.nl/lFwXNz
11 years 13 weeks ago -
@dwilliams5 (Dennis Williams)
just completed a runtastic run of 3.02 km in 40 min 11 s with #runtastic #Android App: http://tinyurl.com/5tvrpe3
11 years 13 weeks ago -
@S_Pinz (Spinz!)
RT @Androidheadline: Out of box #LG Optimus 3D got Quadrant 2420 score. Thanks @blink_c #io2011 #android http://twitpic.com/4whkdz
11 years 13 weeks ago -
@tayaitapps (Taya IT)
Next Google TV Looks A Lot Like Android http://t.co/dvlTim3 via @alleyinsider #google #apple #android #tv #honeycomb
11 years 13 weeks ago
Poll
Useful resources
Android Development Projects
- iOS/Android Developer to take older Games and bring them Current
- Android apps developer - need to finish urgent.
- Buliding MobileApp For onlie order
- looking for android APP developers
- Create an ecommerce app
- text-to voice for smartphones IOS - GOOGLE - HARMONY - AND ALEXA
- Optimize Images on App
- Create small feature with drag-drop text for Android
- Scouting for advanced website and Mobile apps developers. Potential Long-term contract.
- BLACK SCREEN