Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.content.Context;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
- import java.util.Properties;
- import javax.activation.DataHandler;
- import javax.mail.*;
- import javax.mail.search.FlagTerm;
- public class Home extends Activity
- {
- Button button;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- addListenerOnButton();
- }
- public void addListenerOnButton() {
- button = (Button) findViewById(R.id.btnGO);
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View arg0) {
- EditText UN = (EditText)findViewById(R.id.txtUN);
- EditText PW = (EditText)findViewById(R.id.txtPW);
- String userName = UN.getText().toString();
- String password = PW.getText().toString();
- exec(userName,password);
- //To change body of implemented methods use File | Settings | File Templates.
- }
- });
- }
- public void exec(String user, String pass){
- Properties props = System.getProperties();
- props.setProperty("mail.store.protocol", "imaps");
- try {
- Session session = Session.getDefaultInstance(props, null);
- Store store = session.getStore("imaps");
- store.connect("imap.gmail.com", user, pass);
- //System.out.println(store);
- Folder inbox = store.getFolder("Inbox");
- inbox.open(Folder.READ_WRITE);
- int unread = inbox.getUnreadMessageCount();
- FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false) ;
- Message messages[] = inbox.search(ft);
- for(Message message:messages){
- //System.out.print(newline);
- message.setFlag(Flags.Flag.SEEN, true);
- }
- } catch (NoSuchProviderException e) {
- e.printStackTrace();
- System.exit(1);
- } catch (MessagingException e) {
- e.printStackTrace();
- System.exit(2);
- }
- }
- }
Add Comment
Please, Sign In to add comment