Detecting outgoing sms android -


i'm using contentobserver detect outgoing messages. problem onchange() fires 3 times whenever message sent. i've been looking through answers on , appears because 3 tables updated each time message sent.

luckily each message comes unique id can't quite figure out how best filter out messages same id. tried different approaches seem fail.

does know way of doing this?

my contentobserver looks this

    private class outgoingsms extends contentobserver {     public outgoingsms(handler handler) {         super(handler);     }      @override     public boolean deliverselfnotifications(){         return true;     }      @override     public void onchange(boolean selfchange){         super.onchange(selfchange);          uri smsuri = uri.parse("content://sms/sent");         cursor cursor = mcontext.getcontentresolver().query(smsuri, null, null, null, null);         string outgoingsms = null;          if (cursor != null && cursor.movetofirst()){              try{                  cursor.movetofirst();                 string type = cursor.getstring(cursor.getcolumnindex("type"));                  if (type.equals("2")){                      outgoingsms = cursor.getstring(cursor.getcolumnindex("address"));                     string substring = outgoingsms.substring(0, 3);                 }              }             catch (cursorindexoutofboundsexception e){                 log.e(constants.tag, "smshelper: outgoingsms", e);             }             finally{                 cursor.close();             }              //filter out duplicate ids here.              if (outgoingsms != null ){                 long timestamp= gettime();                 datamodel.getinstance(mcontext).addlog(outgoingsms), "sms", timestamp, 0, 1);                 log.d(constants.tag, "smshelper: outgoingsms: " + outgoingsms);              }         }     } } 


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -