1

我正在开发联系表格,以便将电子邮件发送到已修复的特定邮件 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)
4

4 回答 4

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:"));
于 2013-08-14T09:41:52.877 回答
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();
}

否则,您将不得不编写自己的客户端。

于 2013-08-14T09:14:00.417 回答
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" />
于 2013-08-14T09:10:58.753 回答
0

更改 setType()

使用这条线

email.setType("message/rfc822");

代替

email.setType("text/plain");
于 2013-08-14T09:21:06.727 回答