Free Online Courses for Software Developers - MrBool
× Please, log in to give us a feedback. Click here to login
×

You must be logged to download. Click here to login

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

How to send email in Android using Scrolling Layout

In this article we will learn how do we create scrolling layout, send an email using email intent and also how do we use analog clock into an android application.

There might be number of elements into an android layout and these attributes should be scrolled to be viewed into a single android layout. Android contains Scrolling layout option to manage these kinds of layouts. There are several ways to send an email using android device. We will go with email intent to send an email and android also provide a dragging control to display a clock into an android application.

Scrolling, emailing Intent and Clock object with Android in Detail:

While we are having a lot of attributes to be listed into a single android layout, there is a scrolling tag or dragging attribute is provided into android object library that helps us to manage scrolling layout view. Android provides <ScrollView> tag that manages a bundle of attributes of a single layout into scrolling set. It has multiple attributes to manage the view of scrolling list as shown into Listing 1:

Listing 1: ScrollView control of android library

<ScrollView android:layout_width="fill_parent"
    android:layout_weight="30"
    android:layout_height="fill_parent">
.
.
</ScrollView>

Listing 1 list an example of <ScrollView> that defines layout_weight to “30” and layout_height to “fil_parent”. The value “fill_parent” assigns complete height for scrolling view out of assigned weight of the layout.

To send an email using an email Intent, we have to setup an intent that loads email intent as listed into Listing 2:

Listing 2: Create email intent

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 

This intent creates email intent to send an email using Intent action “ACTION_SEND”.

Once email intent has been created, we are required to set up email parameters like email address, email subject, email contents type and email message as listed into Listing 3:

Listing 3: Setup email intents parameters

emailIntent.putExtra(android.content.Intent.ACTION_SEND, emailAddress);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailAddress);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, ets2);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);

Listing 3 creates email intent parameters like email address, email subject, email content type and email message using Intent class actions EXTRA_EMAIL, EXTRA_SUBJECT, plain/text, and EXTRA_TEXT.

To create an analog clock into an android application, android control library provides control <AnalogClock> with its properties as listed in Listing 4:

Listing 4: AnalogClock

<AnalogClock
    android:id="@+id/analogClock1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />

Listing 4 defines <AnalogClock> object with its attributes and their values. The attribute android:id helps to access this object into android activity class, whereas android:layout_width and android:height are used to setup it’s default width and height using value wrap_content.

Let’s create an application that will use these three objects in itself, where scrolling will manage email parameter attributes to be seen into a single layout view and email intent will send an email and analog clock will show the current device time into this application.

Let’s define a layout email.xml into Listing 5 as:

Listing 5: email.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"    
    tools:context=".MainActivity"
    android:layout_weight="100" >
<ScrollView android:layout_width="fill_parent"
    android:layout_weight="30"
    android:layout_height="fill_parent">
    <LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="Email:" />
    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
	<TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Subject:" />

    
    <EditText
        android:id="@+id/editText2"
       android:layout_width="match_parent"
        android:layout_height="match_parent"
		/>
	<TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Your Name:" />

    <EditText
        android:id="@+id/editText3"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
    	/>
	<TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Your Email:" />

        
    <EditText
        android:id="@+id/editText4"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
<TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Reason to contact:" />

        
    <EditText
        android:id="@+id/editText5"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
	<TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Comments:" />

    <EditText
        android:id="@+id/editText6"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</LinearLayout>

</ScrollView>
<LinearLayout android:orientation="vertical"
    android:layout_weight="40"
    android:layout_width="match_parent"
    android:layout_height="fill_parent">
    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="Submit" />
</LinearLayout>
<LinearLayout android:orientation="vertical"
    android:layout_weight="30"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:gravity="center">
<AnalogClock
    android:id="@+id/analogClock1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />
</LinearLayout>
</LinearLayout>

Listing 5 defines 6 <EditText> and <TextViews>, These <EditText> will be used to gather information from user and will be assigned into email form to send an email. A <Button> will be created to start send an email and <AnalogClock> creates an analog clock to view current device timing.

Now, Let’s define MainActivity.java java action action class file that will help to manage email application to send an email using onClick event of the button as listed into Listing 6:

Listing 6: MainActivity.java

package com.example.test;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity implements View.OnClickListener{
	EditText et1, et2, et3, et4, et5, et6;
	Button sendEmail;
	String ets1, ets2, ets3, ets4, ets5, ets6;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.email);
		getDataFromEditTextBoxes();
		sendEmail.setOnClickListener(this);
	}
	private void getDataFromEditTextBoxes(){
		et1 = (EditText) findViewById(R.id.editText1);
		et2 = (EditText) findViewById(R.id.editText2);
		et3 = (EditText) findViewById(R.id.editText3);
		et4 = (EditText) findViewById(R.id.editText4);
		et5 = (EditText) findViewById(R.id.editText5);
		et6 = (EditText) findViewById(R.id.editText6);
		sendEmail = (Button) findViewById(R.id.button1);
	}
	@Override
	public void onClick(View v) {
		setDataFromEditTextBoxesToString();
		String emailAddress[] = {ets1};
		String message = "Hi,<br/>" + "I am " + ets3 + "." + ets5 + ". My Email is: " + ets4 + "<br/><br/>Regards,<br/>" + ets3;
		Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
		emailIntent.putExtra(android.content.Intent.ACTION_SEND, emailAddress);
		emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailAddress);
		emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, ets2);
		emailIntent.setType("plain/text");
		emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
		startActivity(emailIntent);
	}
	private void setDataFromEditTextBoxesToString(){
		ets1 = et1.getText().toString();
		ets2 = et2.getText().toString();
		ets3 = et3.getText().toString();
		ets4 = et4.getText().toString();
		ets5 = et5.getText().toString();
		ets6 = et6.getText().toString();
	}
	@Override
	protected void onPause(){
		super.onPause();
		finish();
	}
}

Listing 6 defines MainActivit.java class file that inherits Activity class and implements interface OnClickListener of View class. This class dfines 6 String and EditText variables also define Button type variable. It also define getDataFromEditTextBoxes() and setDataFromEditTextBoxesToString() method and overrides onCreate(), onPause() and onClick() methods. onClick() method creates email intents and make ready an email to be sent, onPause() method is used to finish an application, when the task is done and onCreate() method is used to initialize an email application to send an email, it initialize the onClick listener that reads the email inputs and assign it to email intent to make ready for sending an email.

Now lets define AndroidManifest.xml file that will help to configure an initialize an android application as listed into Listing 7:

Listing 7: AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.test"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="8" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.test.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Listing 7 defines AndroidManifest.xml file that defines set of tag that defines document type, supporting minimum and maximum android api, application information like application name and launcher information, it also define activity information for email and define this activity as main action or the launcher activity.

Now, Let’s run this application, to run this application, right click on the project directory and go to “Run As” and “Android Application” that takes some time to be launched an application into the android emulator as shown into Figure 1 and Figure 2:

SendEmail Application

Figure 1: SendEmail Application

Scrolling Email Information

Figure 2: Scrolling Email Information

While we hit “submit” button, it make ready our email information to be sent on the given email address. I gave same email address everywhere, so don’t be confuse. Let’s go with Figure 3 that shows email ready to be sent.

Email to be sent

Figure 3: Email to be sent

Figure 4 and Figure 5 shows the received email into the inbox as:

Emails Queue list received email on top

Figure 4 : Emails Queue list received email on top

Shows opened email

Figure 5: Shows opened email

Figure 4 lists the received email at the top and figure 5 shows the opened email that was send and received.

Conclusion:

So, at the end of this article, we came to learn about using and into our android application, we are also now able to send an email using our personal android application that uses android email intent to send an email.



Have more than 5 years experience about Java, .Net, C and C++.

What did you think of this post?
Services
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login