2011. 8. 9. 10:32
모바일/안드로이드
* 출처 (Source) : http://www.helloandroid.com/tutorials/how-send-email-your-application
How to send email from your application
SDK Version:
M3 Today we'll create an easy email sender application.
First of all we need to create a layout to set the address, the subject and email body box.
-
<?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.c
om/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&quo
t; android:text="Send!" -
-
android:width="150dip"></Button>
-
</LinearLayout>
Ugly, but works...
Next we create a new class, called ....uhhhm...Email, then modify like this:
-
import android.app.Activity;
-
import android.content.Intent;
-
import android.os.Bundle;
-
import android.view.View;
-
import android.view.View.OnClickListe
ner ; -
import android.widget.Button;
-
import android.widget.EditText;
-
-
public class Email extends Activity {
-
Button send;
-
EditText address, subject, emailtext;
-
@Override
-
public void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
-
setContentView(R.layout.email);
-
address=(EditText) findViewById(R.id.emailaddress);
-
subject=(EditText) findViewById(R.id.emailsubject);
-
emailtext=(EditText) findViewById(R.id.emailtext);
-
-
send.setOnClickListener(new OnClickListener() {
-
-
@Override
-
// TODO Auto-generated method stub
-
-
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
-
-
emailIntent.setType("plain/text");
-
-
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());
-
-
Email.this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
-
-
}
-
});
-
}
-
}
It will use the button's onclicklistener method to send the email. It does not work on emulator, but works on real devices.
'모바일 > 안드로이드' 카테고리의 다른 글
[링크]AsyncTask and AsyncTaskLoader (1) | 2012.11.29 |
---|---|
TextWatcher (0) | 2011.08.12 |
Android SDK Quick Tip: Sending Pictures the Easy Way (0) | 2011.08.09 |
Debug Certificate expired (1) | 2011.07.06 |
[안드로이드] achartengine (0) | 2011.04.21 |