First you need to add Email/Gmail Account...then choose your email client.... :)
activity_main.xml
--------------------
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_view"
android:textStyle="italic"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_gravity="center_horizontal"
android:textColor="#000099"/>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TO:"
android:textSize="16dip"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000099" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Friends email_id" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subject:"
android:textSize="16dip"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000099" />
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Subject" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message:"
android:textSize="16dip"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000099" />
<EditText
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="94dp"
android:layout_weight="0.40"
android:ems="10"
android:gravity="top"
android:hint="Write Your Message" />
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send"
android:textColor="#000099"
/>
</LinearLayout>
Mainactivity.java
-------------------
package com.kundan.email;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
Button send;
EditText ed1,ed2,ed3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1=(EditText) findViewById(R.id.editText1);
ed2=(EditText) findViewById(R.id.editText2);
ed3=(EditText) findViewById(R.id.editText3);
send=(Button) findViewById(R.id.button1);
send.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String to=ed1.getText().toString();
String subject=ed2.getText().toString();
String message=ed3.getText().toString();
Intent i=new Intent(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_EMAIL, new String[]{to});
i.putExtra(Intent.EXTRA_SUBJECT, subject);
i.putExtra(Intent.EXTRA_TEXT, message);
i.setType("message/rfc822");
startActivity(Intent.createChooser(i, "Choose your email client!!"));
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
activity_main.xml
--------------------
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_view"
android:textStyle="italic"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_gravity="center_horizontal"
android:textColor="#000099"/>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TO:"
android:textSize="16dip"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000099" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Friends email_id" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subject:"
android:textSize="16dip"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000099" />
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Subject" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message:"
android:textSize="16dip"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000099" />
<EditText
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="94dp"
android:layout_weight="0.40"
android:ems="10"
android:gravity="top"
android:hint="Write Your Message" />
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send"
android:textColor="#000099"
/>
</LinearLayout>
Mainactivity.java
-------------------
package com.kundan.email;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
Button send;
EditText ed1,ed2,ed3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1=(EditText) findViewById(R.id.editText1);
ed2=(EditText) findViewById(R.id.editText2);
ed3=(EditText) findViewById(R.id.editText3);
send=(Button) findViewById(R.id.button1);
send.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String to=ed1.getText().toString();
String subject=ed2.getText().toString();
String message=ed3.getText().toString();
Intent i=new Intent(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_EMAIL, new String[]{to});
i.putExtra(Intent.EXTRA_SUBJECT, subject);
i.putExtra(Intent.EXTRA_TEXT, message);
i.setType("message/rfc822");
startActivity(Intent.createChooser(i, "Choose your email client!!"));
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
No comments:
Post a Comment