We can send an email with the attachment , for this purpose make a project with the name EmailWithAttachment and have a main java acticity as
1)Main.java
package com.example.emailandroid;
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;
public class Main extends Activity implements OnClickListener {
private static final String TAG = "Main";
private Button emailButton;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Set the View Layer
setContentView(R.layout.main);
// Get reference to Email Button
this.emailButton = (Button) this.findViewById(R.id.emailButton);
// Sets the Event Listener onClick
this.emailButton.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (view == this.emailButton) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_TITLE, "My Title");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My Subject");
// Obtain reference to (hard-coded) String and pass it to Intent
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
getString(R.string.my_text));
startActivity(emailIntent);
}
}
}
1)Main.java
package com.example.emailandroid;
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;
public class Main extends Activity implements OnClickListener {
private static final String TAG = "Main";
private Button emailButton;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Set the View Layer
setContentView(R.layout.main);
// Get reference to Email Button
this.emailButton = (Button) this.findViewById(R.id.emailButton);
// Sets the Event Listener onClick
this.emailButton.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (view == this.emailButton) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_TITLE, "My Title");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My Subject");
// Obtain reference to (hard-coded) String and pass it to Intent
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
getString(R.string.my_text));
startActivity(emailIntent);
}
}
}
2)res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/emailButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email" />
</LinearLayout>
3) res/values/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">EmailAndroid</string>
<string name="hello">Hello World, EmailAndroidActivity!</string>
<string name="my_text">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem
Ipsum has been the industry\'s standard dummy text ever since the 1500s, when
an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries, but also the leap into
electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker
including versions of Lorem Ipsum.
</string>
</resources>
screenshots==>
Hi,
ReplyDeleteRecently I came across some great articles on your site.
The other day, I was discussing (http://upadhyayjiteshandroid.blogspot.in/2013/03/android-email-with-some-attachment.html)with my colleagues and they suggested I submit an article of my own. Your site is just perfect for what I have written!
Would it be ok to submit the article? It is free of charge, of course!
Let me know what you think
Contact me at anelieivanova@gmail.com
Regards
Anelie Ivanova