Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion hi...
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Asheesh Arya  
View profile  
 More options Sep 17 2012, 1:56 am
From: Asheesh Arya <asheesharya...@gmail.com>
Date: Mon, 17 Sep 2012 11:24:50 +0530
Local: Mon, Sep 17 2012 1:54 am
Subject: Re: [android-developers] hi...

this is the code to send a mail with attachment
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();}
                 }
        });
        }
    }
--------------------------------------------------------------------------- --------------------------------------------------------------------------- -------

xml file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"

android:layout_width="fill_parent" android:layout_height="fill_parent"

xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"
android:background="#6699FF">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text=""
android:id="@+id/fileContent" />

<LinearLayout android:id="@+id/LinearLayout02"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:orientation="horizontal">

<EditText android:layout_width="wrap_content"

android:layout_height="wrap_content" android:width="170dip"

android:id="@+id/emailaddress"></EditText>

<TextView android:layout_width="wrap_content"

android:layout_height="wrap_content" android:id="@+id/emailaddress"

android:text="Email address"></TextView>

</LinearLayout>

<LinearLayout android:id="@+id/LinearLayout03"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:orientation="horizontal">

<EditText android:layout_width="wrap_content"

android:layout_height="wrap_content" android:width="170dip"

android:id="@+id/emailsubject"></EditText>

<TextView android:layout_width="wrap_content"

android:layout_height="wrap_content" android:id="@+id/emailsubject"

android:text="Subject"></TextView>

</LinearLayout>

<EditText android:layout_width="wrap_content"

android:layout_height="wrap_content" android:lines="5"
android:width="300dip"

android:id="@+id/emailtext"></EditText>

<Button android:layout_width="wrap_content"

android:layout_height="wrap_content" android:id="@+id/emailsendbutton"

android:text="Send!" android:width="150dip"></Button>

</LinearLayout>
--------------------------------------------------------------------------- ---------------------------------------------------------------------
dont forget to add internet permission in your android manifest file
PS for sending a mail test this code on real device not on emulator


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.