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>
EmailActivity.java
package com.email;
import java.io.File;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
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 EmailActivity extends Activity {
File attachment;
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
File root = Environment.getExternalStorageDirectory();
String fileName = "Feedback.db";
if (root.canWrite()) {
attachment = new File(root, fileName);
}
final Intent emailIntent = new Intent(
android.content.Intent.ACTION_SEND);
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(android.content.Intent.EXTRA_TEXT,
emailtext.getText());
emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(attachment));
EmailActivity.this.startActivity(Intent.createChooser(emailIntent,
"Send mail..."));
}
});
}
}
Source code here..
No comments:
Post a Comment