2011-08-22 47 views
4

接收電子郵件我是新到Android編程。如何從Android版Gmail

我得到了我的Gmail帳戶應用發送電子郵件。 我現在需要的是如何接收來自G郵件的新電子郵件? 或者至少如何得到我的收件箱中有新郵件的通知?

我不想使用Gmail應用程序從市場或嵌入電子郵件Android應用或使...我做我自己的應用程序管理Gmail帳戶(如在自己的應用程序某種小部件)。

+0

我不知道我得到了它,請確認。你想讓你的應用程序接收電子郵件?所以應用程序會得到並閱讀這些電子郵件? – Shlublu

+0

您可以在模擬器中設置您的Gmail帳戶,並在模擬器中獲取郵件。 –

回答

3

爲了實現這個功能,首先需要建立與Gmail服務器的連接,那麼你需要檢查收件箱文件夾中是否有新郵件。如果找到,則使用NotificationManager將通知發送給用戶。請點擊此鏈接http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_%28no_Intents%29_in_Android和另一個鏈接是

Sending Email in Android using JavaMail API without using the default/built-in app

+0

TNX,我得到這個工作在某種程度上:) – Veljko

+0

@Veljko請告訴我,你是怎麼做到這???? –

+0

你好,我一年前在做這件事......我很確定我找到了解這個鏈接的解決方案。祝你好運! – Veljko

2

試試這個:

Properties props = new Properties(); 
    //IMAPS protocol 
    props.setProperty(「mail.store.protocol」, 「imaps」); 
    //Set host address 
    props.setProperty(「mail.imaps.host」, imaps.gmail.com); 
    //Set specified port 
    props.setProperty(「mail.imaps.port」, 「993″); 
    //Using SSL 
    props.setProperty(「mail.imaps.socketFactory.class」, 「javax.net.ssl.SSLSocketFactory」); 
    props.setProperty(「mail.imaps.socketFactory.fallback」, 「false」); 
    //Setting IMAP session 
    Session imapSession = Session.getInstance(props); 

Store store = imapSession.getStore(「imaps」); 
//Connect to server by sending username and password. 
//Example mailServer = imap.gmail.com, username = abc, password = abc 
store.connect(mailServer, account.username, account.password); 
//Get all mails in Inbox Forlder 
inbox = store.getFolder(「Inbox」); 
inbox.open(Folder.READ_ONLY); 
//Return result to array of message 
Message[] result = inbox.getMessages(); 
+0

的一些背景信息將是很好。 Session和Store的命名空間是什麼? – anhoppe