connect android app to gmail server using asyntask -


i developing android app. connect gmail server , read inbox emails. implement connection , email reading code, problem when app. getting connecting gmail server app. hangs , when reads email gmail server become stop working while , runs. want put connect , read email code in background using asyntask. please tell how implement connect , read email code using asyntask in android app. not hang or crash or stop?

public void readgmail(string host, string storetype, string user, string password, sqlitedatabase database) {     try {         properties properties = new properties();         properties.put("mail.pop3.host", host);         properties.put("mail.pop3.port", "995");         properties.put("mail.pop3.starttls.enable", "true");         session emailsession = session.getdefaultinstance(properties);         store = emailsession.getstore("pop3s");         store.connect(host, user, password);         folder emailfolder = store.getfolder("inbox");         emailfolder.open(folder.read_only);         message[] messages = emailfolder.getmessages();         (int = 0; < messages.length; i++) {             message message = messages[i];             object obj = message.getcontent();             int email = message.getmessagenumber();             string subject = message.getsubject();             string emaildatetime = string.valueof(message.getsentdate());             string = string.valueof(message.getfrom()[0]);             string sendfrom=from.substring(from.indexof("<") + 1, from.indexof(">"));             multipart mp = (multipart) message.getcontent();             bodypart bp = ((multipart) message.getcontent()).getbodypart(0);             if (bp.ismimetype("text/plain")) {                 string body = (string) bp.getcontent();                 addemail addemail = new addemail();                 dbhelper dbhelper = new dbhelper(getapplicationcontext());                 //sqlitedatabase database = dbhelper.getwritabledatabase();                 addemail.emailinsert(sendfrom, subject, body, emaildatetime, "pending...", "", data.getuseremail, data.getuserpassword, database);             }         }          (int = 0, n = messages.length; < n; i++) {             message message = messages[i];             system.out.println("email number " + (i + 1));         }         //smssendactivity smssendactivity = new smssendactivity();         //smssendactivity.smsperodictimer(database);         emailfolder.close(false);         store.close();     } catch (nosuchproviderexception e) {         e.printstacktrace();     } catch (messagingexception e) {         e.printstacktrace();     } catch (exception e) {         e.printstacktrace();     } } 


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -