Thanks for the sample code.
I have some specific requirement, like in my Email composer in want add feature like Bold, underline and italic for text typed.
Also font change(color and size) for the text in composer screen.
Do let me know in case you have any idea about that.
Thanks
Amit sinha
On Thu, Oct 18, 2012 at 11:11 AM, Asheesh Arya <asheesharya.cs@gmail.com> wrote:
code to create and send email programmatically in android
import java.io.File;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class sendemail extends Activity {
Button send;
EditText address, subject, emailtext;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main11);
send = (Button) findViewById(R.id.emailsendbutton);
address = (EditText) findViewById(R.id.emailaddress);
subject = (EditText) findViewById(R.id.emailsubject);
emailtext = (EditText) findViewById(R.id.emailtext);
final TextView tv = (TextView)findViewById(R.id.fileContent);
send.setOnClickListener(new OnClickListener() {
// TextView tv = (TextView)findViewById(R.id.fileContent);
public void onClick(View v) {
// TODO Auto-generated method stub
if(!address.getText().toString().trim().equalsIgnoreCase("")){
// Toast.makeText(getApplicationContext(), "Please enter an email address..", Toast.LENGTH_LONG).show();
File dir = Environment.getExternalStorageDirectory();
File file = new File(dir,"download/phonedata.txt");
if (file.exists())
try {
Log.i(getClass().getSimpleName(), "send task - start");
final Intent emailIntent = new Intent(
android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
// emailIntent.setType("application/octet-stream");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { address.getText().toString() });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText());
emailIntent.putExtra(Intent.EXTRA_STREAM,
Uri.parse("file://" + file));
Toast.makeText(sendemail.this, "File successfully attached in your Mail!!!",
Toast.LENGTH_LONG).show();
tv.setText("File Successfully attached in your mail!!!");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext.getText());
sendemail.this.startActivity(Intent
.createChooser(emailIntent, "Send mail..."));
} catch (Throwable t) {
Toast.makeText(sendemail.this, "Request failed: " + t.toString(),
Toast.LENGTH_LONG).show();
}
else
{
tv.setText("Sorry file doesn't exist!!!");
Toast.makeText(sendemail.this, "File not found in sd-card....Please upload it from Server!!!",
Toast.LENGTH_LONG).show();
//Toast.makeText(getApplicationContext(), "Please enter an email address..", Toast.LENGTH_LONG).show();
}
}
else
{
Toast.makeText(getApplicationContext(), "Please enter an email address..", Toast.LENGTH_LONG).show();}
}
});}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
No comments:
Post a Comment