Android
|
Modified: |
Overview

Email client is invoked by an Intent that is passed extra data for receiver, cc, bcc, subject, and body fields.
Works only on real devices, not emulator.
Need an email account setup on the device.
Example
package edu.ius.rwisman.EmailSend;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class EmailSendActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onClick(View v) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String emailList[] = { "user1@fakehost.com","user2@fakehost.com" };
String ccList[] = { "user3@fakehost.com","user4@fakehost.com"};
String bccList[] = { "user5@fakehost.com" };
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailList);
emailIntent.putExtra(android.content.Intent.EXTRA_CC, ccList);
emailIntent.putExtra(android.content.Intent.EXTRA_BCC, bccList);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My subject");
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "My message.");
startActivity(emailIntent);
}
}
|
main.xml supplies the Send Button.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
android:onClick="onClick"/>
</LinearLayout>
|
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.ius.rwisman.EmailSend"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".EmailSendActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
|