在android中使用java邮件api

gwo2fgha  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(359)

我正在研究一个需要访问gmail消息的android应用程序,我为这个东西创建了一个类,并通过activity的oncreate()方法调用它。
messagebox.java文件

public void startConnection(String userName, String password) throws MessagingException {

            Properties properties = System.getProperties();
            properties.setProperty("mail.store.protocol", "imaps");
            properties.setProperty("mail.imaps.host","imaps.gmail.com");
            properties.setProperty("mail.imaps.quitwait", "false");
            properties.put("mail.imaps.auth", "true"); 
            properties.put("mail.imaps.port", "993"); 
            properties.put("mail.imaps.socketFactory.port", "993"); 
            properties.put("mail.imaps.socketFactory.class", 
                      "javax.net.ssl.SSLSocketFactory"); 
            properties.put("mail.imaps.socketFactory.fallback", "false"); 
            session = Session.getDefaultInstance(properties, null);

                store = session.getStore("imaps");
 **Problem in here**store.connect("imap.gmail.com", userName, password);
        }

我的活动

try  {
            messageBox.startConnection("username","password");

        } catch (MessagingException e) {
            e.printStackTrace();
        }

这里怎么了?提前谢谢
编辑:来自logcat

06-06 12:31:11.125: E/ThrottleService(289): problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory)
06-06 12:31:13.493: E/ActivityThread(653): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d085b0 that was originally bound here
06-06 12:31:13.493: E/ActivityThread(653): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d085b0 that was originally bound here
06-06 12:31:13.493: E/ActivityThread(653):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
06-06 12:31:13.493: E/ActivityThread(653):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
06-06 12:31:13.493: E/ActivityThread(653):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
06-06 12:31:13.493: E/ActivityThread(653):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
06-06 12:31:13.493: E/ActivityThread(653):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
06-06 12:31:13.493: E/ActivityThread(653):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
06-06 12:31:13.493: E/ActivityThread(653):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
06-06 12:31:13.493: E/ActivityThread(653):  at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
06-06 12:31:13.493: E/ActivityThread(653):  at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
06-06 12:31:13.493: E/ActivityThread(653):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
06-06 12:31:13.493: E/ActivityThread(653):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
06-06 12:31:13.493: E/ActivityThread(653):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
06-06 12:31:13.493: E/ActivityThread(653):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-06 12:31:13.493: E/ActivityThread(653):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-06 12:31:13.493: E/ActivityThread(653):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-06 12:31:13.493: E/ActivityThread(653):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-06 12:31:13.493: E/ActivityThread(653):  at java.lang.Thread.run(Thread.java:856)
06-06 12:31:13.524: E/StrictMode(653): null
06-06 12:31:13.524: E/StrictMode(653): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d085b0 that was originally bound here
06-06 12:31:13.524: E/StrictMode(653):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
06-06 12:31:13.524: E/StrictMode(653):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
06-06 12:31:13.524: E/StrictMode(653):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
06-06 12:31:13.524: E/StrictMode(653):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
06-06 12:31:13.524: E/StrictMode(653):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
06-06 12:31:13.524: E/StrictMode(653):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
06-06 12:31:13.524: E/StrictMode(653):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
06-06 12:31:13.524: E/StrictMode(653):  at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
06-06 12:31:13.524: E/StrictMode(653):  at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
06-06 12:31:13.524: E/StrictMode(653):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
06-06 12:31:13.524: E/StrictMode(653):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
06-06 12:31:13.524: E/StrictMode(653):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
06-06 12:31:13.524: E/StrictMode(653):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-06 12:31:13.524: E/StrictMode(653):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-06 12:31:13.524: E/StrictMode(653):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-06 12:31:13.524: E/StrictMode(653):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-06 12:31:13.524: E/StrictMode(653):  at java.lang.Thread.run(Thread.java:856)
06-06 12:31:13.565: E/ActivityThread(653): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d080d8 that was originally bound here
06-06 12:31:13.565: E/ActivityThread(653): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d080d8 that was originally bound here
06-06 12:31:13.565: E/ActivityThread(653):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
06-06 12:31:13.565: E/ActivityThread(653):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
06-06 12:31:13.565: E/ActivityThread(653):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
06-06 12:31:13.565: E/ActivityThread(653):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
06-06 12:31:13.565: E/ActivityThread(653):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
06-06 12:31:13.565: E/ActivityThread(653):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
06-06 12:31:13.565: E/ActivityThread(653):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
06-06 12:31:13.565: E/ActivityThread(653):  at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
06-06 12:31:13.565: E/ActivityThread(653):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
06-06 12:31:13.565: E/ActivityThread(653):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
06-06 12:31:13.565: E/ActivityThread(653):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
06-06 12:31:13.565: E/ActivityThread(653):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-06 12:31:13.565: E/ActivityThread(653):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-06 12:31:13.565: E/ActivityThread(653):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-06 12:31:13.565: E/ActivityThread(653):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-06 12:31:13.565: E/ActivityThread(653):  at java.lang.Thread.run(Thread.java:856)
06-06 12:31:13.613: E/StrictMode(653): null
06-06 12:31:13.613: E/StrictMode(653): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d080d8 that was originally bound here
06-06 12:31:13.613: E/StrictMode(653):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
06-06 12:31:13.613: E/StrictMode(653):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
06-06 12:31:13.613: E/StrictMode(653):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
06-06 12:31:13.613: E/StrictMode(653):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
06-06 12:31:13.613: E/StrictMode(653):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
06-06 12:31:13.613: E/StrictMode(653):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
06-06 12:31:13.613: E/StrictMode(653):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
06-06 12:31:13.613: E/StrictMode(653):  at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
06-06 12:31:13.613: E/StrictMode(653):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
06-06 12:31:13.613: E/StrictMode(653):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
06-06 12:31:13.613: E/StrictMode(653):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
06-06 12:31:13.613: E/StrictMode(653):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-06 12:31:13.613: E/StrictMode(653):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-06 12:31:13.613: E/StrictMode(653):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-06 12:31:13.613: E/StrictMode(653):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-06 12:31:13.613: E/StrictMode(653):  at java.lang.Thread.run(Thread.java:856)
06-06 12:32:03.693: E/ActivityThread(653): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d2ebc0 that was originally bound here
06-06 12:32:03.693: E/ActivityThread(653): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d2ebc0 that was originally bound here
06-06 12:32:03.693: E/ActivityThread(653):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
06-06 12:32:03.693: E/ActivityThread(653):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
06-06 12:32:03.693: E/ActivityThread(653):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
06-06 12:32:03.693: E/ActivityThread(653):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
06-06 12:32:03.693: E/ActivityThread(653):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
06-06 12:32:03.693: E/ActivityThread(653):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
06-06 12:32:03.693: E/ActivityThread(653):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
06-06 12:32:03.693: E/ActivityThread(653):  at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
06-06 12:32:03.693: E/ActivityThread(653):  at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
06-06 12:32:03.693: E/ActivityThread(653):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
06-06 12:32:03.693: E/ActivityThread(653):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
06-06 12:32:03.693: E/ActivityThread(653):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
06-06 12:32:03.693: E/ActivityThread(653):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-06 12:32:03.693: E/ActivityThread(653):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-06 12:32:03.693: E/ActivityThread(653):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-06 12:32:03.693: E/ActivityThread(653):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-06 12:32:03.693: E/ActivityThread(653):  at java.lang.Thread.run(Thread.java:856)
06-06 12:32:03.863: E/StrictMode(653): null
06-06 12:32:03.863: E/StrictMode(653): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d2ebc0 that was originally bound here
06-06 12:32:03.863: E/StrictMode(653):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
06-06 12:32:03.863: E/StrictMode(653):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
06-06 12:32:03.863: E/StrictMode(653):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
06-06 12:32:03.863: E/StrictMode(653):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
06-06 12:32:03.863: E/StrictMode(653):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
06-06 12:32:03.863: E/StrictMode(653):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
06-06 12:32:03.863: E/StrictMode(653):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
06-06 12:32:03.863: E/StrictMode(653):  at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
06-06 12:32:03.863: E/StrictMode(653):  at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
06-06 12:32:03.863: E/StrictMode(653):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
06-06 12:32:03.863: E/StrictMode(653):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
06-06 12:32:03.863: E/StrictMode(653):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
06-06 12:32:03.863: E/StrictMode(653):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-06 12:32:03.863: E/StrictMode(653):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-06 12:32:03.863: E/StrictMode(653):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-06 12:32:03.863: E/StrictMode(653):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-06 12:32:03.863: E/StrictMode(653):  at java.lang.Thread.run(Thread.java:856)
06-06 12:32:03.933: E/ActivityThread(653): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d2e680 that was originally bound here
06-06 12:32:03.933: E/ActivityThread(653): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d2e680 that was originally bound here
06-06 12:32:03.933: E/ActivityThread(653):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
06-06 12:32:03.933: E/ActivityThread(653):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
06-06 12:32:03.933: E/ActivityThread(653):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
06-06 12:32:03.933: E/ActivityThread(653):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
06-06 12:32:03.933: E/ActivityThread(653):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
06-06 12:32:03.933: E/ActivityThread(653):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
06-06 12:32:03.933: E/ActivityThread(653):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
06-06 12:32:03.933: E/ActivityThread(653):  at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
06-06 12:32:03.933: E/ActivityThread(653):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
06-06 12:32:03.933: E/ActivityThread(653):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
06-06 12:32:03.933: E/ActivityThread(653):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
06-06 12:32:03.933: E/ActivityThread(653):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-06 12:32:03.933: E/ActivityThread(653):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-06 12:32:03.933: E/ActivityThread(653):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-06 12:32:03.933: E/ActivityThread(653):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-06 12:32:03.933: E/ActivityThread(653):  at java.lang.Thread.run(Thread.java:856)
06-06 12:32:04.063: E/StrictMode(653): null
06-06 12:32:04.063: E/StrictMode(653): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d2e680 that was originally bound here
06-06 12:32:04.063: E/StrictMode(653):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
06-06 12:32:04.063: E/StrictMode(653):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
06-06 12:32:04.063: E/StrictMode(653):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
06-06 12:32:04.063: E/StrictMode(653):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
06-06 12:32:04.063: E/StrictMode(653):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
06-06 12:32:04.063: E/StrictMode(653):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
06-06 12:32:04.063: E/StrictMode(653):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
06-06 12:32:04.063: E/StrictMode(653):  at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
06-06 12:32:04.063: E/StrictMode(653):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
06-06 12:32:04.063: E/StrictMode(653):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
06-06 12:32:04.063: E/StrictMode(653):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
06-06 12:32:04.063: E/StrictMode(653):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-06 12:32:04.063: E/StrictMode(653):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-06 12:32:04.063: E/StrictMode(653):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-06 12:32:04.063: E/StrictMode(653):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-06 12:32:04.063: E/StrictMode(653):  at java.lang.Thread.run(Thread.java:856)
06-06 12:32:53.943: E/ActivityThread(653): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cef940 that was originally bound here
06-06 12:32:53.943: E/ActivityThread(653): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cef940 that was originally bound here
06-06 12:32:53.943: E/ActivityThread(653):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
06-06 12:32:53.943: E/ActivityThread(653):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
06-06 12:32:53.943: E/ActivityThread(653):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
06-06 12:32:53.943: E/ActivityThread(653):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
06-06 12:32:53.943: E/ActivityThread(653):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
06-06 12:32:53.943: E/ActivityThread(653):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
06-06 12:32:53.943: E/ActivityThread(653):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
06-06 12:32:53.943: E/ActivityThread(653):  at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
06-06 12:32:53.943: E/ActivityThread(653):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
06-06 12:32:53.943: E/ActivityThread(653):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
06-06 12:32:53.943: E/ActivityThread(653):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
06-06 12:32:53.943: E/ActivityThread(653):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-06 12:32:53.943: E/ActivityThread(653):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-06 12:32:53.943: E/ActivityThread(653):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-06 12:32:53.943: E/ActivityThread(653):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-06 12:32:53.943: E/ActivityThread(653):  at java.lang.Thread.run(Thread.java:856)
06-06 12:32:53.963: E/StrictMode(653): null
06-06 12:32:53.963: E/StrictMode(653): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cef940 that was originally bound here
06-06 12:32:53.963: E/StrictMode(653):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
06-06 12:32:53.963: E/StrictMode(653):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
06-06 12:32:53.963: E/StrictMode(653):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
06-06 12:32:53.963: E/StrictMode(653):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
06-06 12:32:53.963: E/StrictMode(653):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
06-06 12:32:53.963: E/StrictMode(653):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
06-06 12:32:53.963: E/StrictMode(653):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
06-06 12:32:53.963: E/StrictMode(653):  at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
06-06 12:32:53.963: E/StrictMode(653):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
06-06 12:32:53.963: E/StrictMode(653):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
06-06 12:32:53.963: E/StrictMode(653):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
06-06 12:32:53.963: E/StrictMode(653):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-06 12:32:53.963: E/StrictMode(653):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-06 12:32:53.963: E/StrictMode(653):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-06 12:32:53.963: E/StrictMode(653):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-06 12:32:53.963: E/StrictMode(653):  at java.lang.Thread.run(Thread.java:856)
d6kp6zgx

d6kp6zgx1#

在emulator中禁用exchange服务解决了此错误:(使用“设置”->“应用”->“全部”->“exchange服务”->“禁用”)

android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d085b0 that was originally bound here

由于使用android4.2.2,我不得不在活动中使用asynctask进行网络操作。这个代码对我有用:

public void MyActivity extends Activity{

public void onCreate(Bundle savedInstanceState){

     new  MyAsyncTaskClass().execute();
}

//internal class
public class MyAsyncTaskClass extends AsyncTask<Void, Void, Void>{

    @Override
    protected Void doInBackground(Void... arg0) {
            Properties properties = new Properties();
        properties.setProperty("mail.imaps.host", "imap.gmail.com"); 
            properties.setProperty("mail.imaps.auth", "true"); 
            properties.setProperty("mail.imaps.debug", "true"); 
            properties.setProperty("mail.imaps.port", "993");
            properties.setProperty("mail.store.protocol", "imaps");
        session = Session.getInstance(properties);

            store = session.getStore("imaps");
            store.connect("imap.gmail.com", 993, userName, password);
            return null;
      }

    }
}

相关问题