Hello folks,

Currently I have some curious where I can find the sms that is just
arrived.
Means, I have a code like below, but can't get the latest one in the
onReceive method.

I can get the SMS contents that is just arrived from pdu in below
code, but can't find it in content://sms/inbox. it has whole of
messages that were sent except the last one that I can see in pdu.

Would you guys please let me know where I can find the SMS that is
just arrived and be seeing in onReceive method?

(My last goal is find it and delete it, actually, if I can abort the
SMS broadcast intent, it would be the best way.)

Please let me have some idea.
Thanks in advance =)

public class MyReceiver extends BroadcastReceiver   {

@Override
public void onReceive(Context context, Intent intent) {

 StringBuilder sb = new StringBuilder();
 Bundle bundle = intent.getExtras();

 if (bundle != null) {
   Object[] pdusObj = (Object[])bundle.get("pdus");
   SmsMessage[] messages = new SmsMessage[pdusObj.length];
   for(int i = 0; i < pdusObj.length; i++) {
     messages[i] = SmsMessage.createFromPdu((byte[])pdusObj[i]);
   }

   Uri uriSms = Uri.parse("content://sms/inbox");
   Cursor c = context.getContentResolver().query(uriSms,
null,null,null,null);
   if (c != null) {
       try {
        System.out.println("c.getCount() : " + c.getCount() + "");
        while (c.moveToNext()) {
                System.out.println("--------------------");
                for (int i = 1; i <= c.getColumnCount(); i++) {
                        System.out.print(i + ":" + c.getColumnName
(i-1) + ": ");
                        try {
                                System.out.println(c.getString(i));
                                } catch (Exception e)
{ System.out.println(e); }

        }

        }
        try {
                setOrderedHint(true);
                abortBroadcast();

                } catch (Exception e) { System.out.println(e);}
       } finally {
         c.close();
       }

   }
 }

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to