0

Possible Duplicate:
How to access the SMS storage on Android?

I am trying to access all messages in android. I have code but I accessed only last message through this code. how can read all?

public void onReceive(Context context, Intent intent) 
{
    //---get the SMS message passed in---
    Bundle bundle = intent.getExtras();        
    SmsMessage[] msgs = null;           
    if (bundle != null)
    {
        String header = "";
        String body = "";

        //---retrieve the SMS message received---
        Object[] pdus = (Object[]) bundle.get("pdus");
        msgs = new SmsMessage[pdus.length];            
        for (int i=0; i<msgs.length; i++)
        {
            msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);                
            header = msgs[i].getOriginatingAddress();                     
            body = msgs[i].getMessageBody().toString();       
        }
        //---display the new SMS message---
        Toast.makeText(context,"Mesaj geldi", Toast.LENGTH_SHORT).show();
        Header.add(header);
        Body.add(body);  
    }
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • possible duplicate of [How to access the SMS storage on Android?](http://stackoverflow.com/questions/4809874/how-to-access-the-sms-storage-on-android) and http://stackoverflow.com/questions/848728/how-can-i-read-sms-messages-from-the-inbox-programmatically-in-android – nandeesh Oct 17 '12 at 08:18
  • that's a receiver for a message. to access the sms database, see http://stackoverflow.com/questions/4809874/how-to-access-the-sms-storage-on-android – njzk2 Oct 17 '12 at 08:42
  • thank you but I didnt find in your receiver.. – yunuus emre Oct 17 '12 at 09:09

1 Answers1

0
Uri allMessage = Uri.parse("content://sms/");
ContentResolver cr = getContentResolver();
Cursor c = cr.query(allMessage, null, null, null, null);
while  (c.moveToNext()) {
   String row = c.getString(1);
}

you can access all messages in android, you can get the all inbox/outbox here , havn't tested it though

Amit Hooda
  • 2,133
  • 3
  • 23
  • 37