Breaking News


Monday 30 December 2013

EMAIL ANDROID TUTORIAL

EMAIL ANDROID TUTORIAL 

How to send email..?
Ans is below....

First Create maillayout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    tools:context=".EmailActivity" >



    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="30dp"
        android:text="Email :"
        android:textAppearance="?android:attr/textAppearanceLarge" />





    <EditText
        android:id="@+id/editText1"
        android:layout_width="230dp"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/textView1"
        android:ems="10" />


    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/editText1"
        android:layout_marginTop="55dp"
        android:text="Subject :"
        android:textAppearance="?android:attr/textAppearanceLarge" />


    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText1"
        android:layout_alignTop="@+id/textView2"
        android:ems="10" >

        <requestFocus />
    </EditText>


    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:text="Message "
        android:textAppearance="?android:attr/textAppearanceLarge" />




    <EditText
        android:id="@+id/editText3"
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:layout_alignLeft="@+id/editText2"
        android:layout_below="@+id/textView3"
        android:ems="10"
        android:inputType="textMultiLine" />




    <Button
        android:id="@+id/button1"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="27dp"
        android:layout_toRightOf="@+id/textView3"
        android:text="Send" />


</RelativeLayout>

After Create MainActivity.java file....

package pack.email;

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

public class EmailActivity extends Activity implements OnClickListener {
Button b;
EditText e1, e2, e3;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
e1 = (EditText) findViewById(R.id.editText1);
e2 = (EditText) findViewById(R.id.editText2);
e3 = (EditText) findViewById(R.id.editText3);
b = (Button) findViewById(R.id.button1);
b.setOnClickListener(this);

}

public void onClick(View v) {
String to = e1.getText().toString();
String sub = e2.getText().toString();
String msg = e3.getText().toString();

Intent mail = new Intent(Intent.ACTION_SEND);
mail.putExtra(Intent.EXTRA_EMAIL, new String[] {to});
mail.putExtra(Intent.EXTRA_SUBJECT, sub);
mail.putExtra(Intent.EXTRA_TEXT, msg);
e1.setText("");
e2.setText("");
e3.setText("");
startActivity(mail);
}

}


And use permission for Internet.....

Run the program......

Share This
Blogger
Facebook
Disqus

comments powered by Disqus

No comments :

Post a Comment

Subscribe
Labels
Popular Posts

Subscribe Via Email

About Us

THIS IS ANDROID AND JAVA FREE TUTORIAL AND ALL PROVIDE SOLUTION IN ANDROID AND JAVA INTERVIEW QUE AND ANS IS AVAILABLE IN MY BLOG AND ANY QUERY PLEASE CONTACT ME GO NOW CONTACT US PAGE.

Total Pageviews

© Android and Java solution All rights reserved | Designed By Fireandroids