tags:

views:

135

answers:

0

I am try to work with abn application ,in which i ty to get list of gmail Inbox in my Custmize list.

Now i want to remove an particular mail from Inbox or mail which come recently. I am trying with this code....but i am confuze how to use Observer class in mainfeast.xml file

import javax.mail.Folder;
import javax.mail.Session;
import javax.mail.Store;

import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Handler;

public class SMSObserver2 extends ContentObserver {

 Context context;

 static Store store;
 static Session session;

 public SMSObserver2(Handler handler) {
  super(handler);
  // TODO Auto-generated constructor stub
  // m_handle = handler;
 }

 public void onChange(boolean bSelfChange) {
  super.onChange(bSelfChange);
  try {
   Folder folder = store.getFolder("INBOX");
   folder.open(Folder.READ_WRITE);

   // Send message to Activity
   // javax.mail.Message msg = new Message();

   // msg.obj = "xxxxxxxxxx";
   // m_handle.sendMessage(msg);
   ContentResolver contentResolver = context.getContentResolver();
   contentResolver.registerContentObserver(Uri
     .parse("content://gmail-ls"), true, this);

   Cursor c = contentResolver.query(Uri.parse("content://gmail-ls/[email protected]"), null, null, null,
     null);

   /*Cursor mailCursor = context.getContentResolver().query(Uri.parse
     ("content://gmail-ls/messages/myownemail@xxxxxxxxx/"), (new String[]
     {"_id", "fromAddress", "subject"}), null, null, null);*/


   while (c.moveToNext()) {
    // Read the contents of the SMS;
    for (int i = 0; i < c.getColumnCount(); i++) {
     String strColumnName = c.getColumnName(i);
     String strColumnValue = c.getString(i);
    }

    // Delete the SMS
    String pid = c.getString(1); // Get thread id;
    String uri = "content://gmail-ls" + pid;
    context.getContentResolver().delete(Uri.parse(uri), null, null);

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

 }
}