2011年5月20日金曜日

AndroidStudyMemo=send email with attached file in

Today i have discussed about how to send email with attached file in
android.

In android u have to give internet permission for android manifest file.

And this application work only from device not in android emulator... so
this think is very important...

And source code given below.

main.xml

<?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">

<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>

And java file given also below.

Email.java

package com.fb

import java.io.file;

import android.app.Activity;

import android.net.Uri;

import android.os.Bundle;

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 Email 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.main);

send = (Button)
findViewById(R.id.emailsendbutton);

address = (EditText)
findViewById(R.id.emailaddress);

subject = (EditText)
findViewById(R.id.emailsubject);

emailtext = (EditText)
findViewById(R.id.emailtext);

send.setOnClickListener(new
OnClickListener() {

@Override

public void
onClick(View v) {

//
TODO Auto-generated method stub

final
Intent emailIntent = new Intent(


android.content.Intent.ACTION_SEND);

emailIntent.setType("image/png");

emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,

new
String[] { address.getText().toString() });

emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,


subject.getText());

emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,


emailtext.getText());

emailIntent.putExtra(Intent.EXTRA_STREAM,
Uri


.parse("android.resource://"


+ getPackageName() + "/" + R.drawable.icon));

FB.this.startActivity(Intent.createChooser(emailIntent,


"Send mail..."));

}

});

}

}

So this are the simple code for send email with attcahed file in android

0 件のコメント:

コメントを投稿