我正在开发联系表格,需要发送电子邮件到特定的邮件ID,这是固定的....请帮助我......
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
buttonSend = (Button) findViewById(R.id.buttonSend);
textTo = (EditText) findViewById(R.id.editTextTo);
textSubject = (EditText) findViewById(R.id.editTextSubject);
textMessage = (EditText) findViewById(R.id.editTextMessage);
buttonSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String to = textTo.getText().toString();
String subject = textSubject.getText().toString();
String message = textMessage.getText().toString();
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"abcdk@gmail.com"});
email.putExtra(Intent.EXTRA_SUBJECT, "subject");
email.putExtra(Intent.EXTRA_TEXT, "message");
email.setType("text/plain");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
}
});
但它不起作用......
08-14 09:11:21.559: E/ActivityThread(552): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d4ad38 that was originally bound here
08-14 09:11:21.559: E/ActivityThread(552): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d4ad38 that was originally bound here
08-14 09:11:21.559: E/ActivityThread(552): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
08-14 09:11:21.559: E/ActivityThread(552): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
08-14 09:11:21.559: E/ActivityThread(552): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
08-14 09:11:21.559: E/ActivityThread(552): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
08-14 09:11:21.559: E/ActivityThread(552): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
08-14 09:11:21.559: E/ActivityThread(552): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
08-14 09:11:21.559: E/ActivityThread(552): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
08-14 09:11:21.559: E/ActivityThread(552): at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
08-14 09:11:21.559: E/ActivityThread(552): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
08-14 09:11:21.559: E/ActivityThread(552): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
08-14 09:11:21.559: E/ActivityThread(552): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
08-14 09:11:21.559: E/ActivityThread(552): at android.os.AsyncTask$2.call(AsyncTask.java:287)
08-14 09:11:21.559: E/ActivityThread(552): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
08-14 09:11:21.559: E/ActivityThread(552): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
08-14 09:11:21.559: E/ActivityThread(552): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
08-14 09:11:21.559: E/ActivityThread(552): at java.lang.Thread.run(Thread.java:856)
08-14 09:11:21.620: E/StrictMode(552): null
08-14 09:11:21.620: E/StrictMode(552): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d4ad38 that was originally bound here
08-14 09:11:21.620: E/StrictMode(552): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
08-14 09:11:21.620: E/StrictMode(552): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
08-14 09:11:21.620: E/StrictMode(552): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
08-14 09:11:21.620: E/StrictMode(552): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
08-14 09:11:21.620: E/StrictMode(552): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
08-14 09:11:21.620: E/StrictMode(552): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
08-14 09:11:21.620: E/StrictMode(552): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
08-14 09:11:21.620: E/StrictMode(552): at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
08-14 09:11:21.620: E/StrictMode(552): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
08-14 09:11:21.620: E/StrictMode(552): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
08-14 09:11:21.620: E/StrictMode(552): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
08-14 09:11:21.620: E/StrictMode(552): at android.os.AsyncTask$2.call(AsyncTask.java:287)
08-14 09:11:21.620: E/StrictMode(552): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
08-14 09:11:21.620: E/StrictMode(552): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
08-14 09:11:21.620: E/StrictMode(552): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
08-14 09:11:21.620: E/StrictMode(552): at java.lang.Thread.run(Thread.java:856)
答案 0 :(得分:0)
对于已发送邮件,请使用以下代码。
final Intent emailIntent = new Intent(
android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { vendoremail });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
_productList.get(0).ProductName);
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
这里..
vendoremail
=电子邮件ID,
_productList.get(0).ProductName
=电子邮件说明
编辑:
您必须在AndroidManifest.xml
文件中授予权限。
<uses-permission android:name="android.permission.INTERNET" />
答案 1 :(得分:0)
最好(也是最简单)的方法是使用Intent:
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
否则你必须自己编写客户端。
答案 2 :(得分:0)
更改setType()
使用此行
email.setType("message/rfc822");
而不是
email.setType("text/plain");
答案 3 :(得分:0)
试试这个
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent .setType("text/plain");
emailIntent .putExtra(Intent.EXTRA_EMAIL , new String[]{"recipientemail@example.com"});
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "subject");
emailIntent .putExtra(Intent.EXTRA_TEXT , "body");
startActivity(Intent.createChooser(emailIntent , "Email:"));