0

I writing some simple application that will look for some message ( sms message ) according to some regular expretion.

I can't access to the message folder - how can i do it ?

Yanshof
  • 9,659
  • 21
  • 95
  • 195

2 Answers2

1

You need to use a content provider to get access to sms messages on android.

The following question helps gives you how to query it.

Android 1.5: Reading SMS messages

Community
  • 1
  • 1
Leif Andersen
  • 21,580
  • 20
  • 67
  • 100
1

You can try something like this (to get the destination address and the sms's body):

    private Cursor smsQuerty() {
            Uri query_content_uri = Uri.parse("content://sms/sent");

        String[] projection = new String[] { "_id", "address", "body" };

        Cursor tCursor = getContentResolver().query(query_content_uri,
                projection, null, null, null);
        startManagingCursor(tCursor);

                    return tCursor;
    }

Than log your cursor to see the data... for example:

private void logCursorForTesting(Cursor cursor) { 
    int colCount = cursor.getColumnCount();
    Log.d(TAG, "Column count is: " + colCount);

    if (cursor != null && cursor.moveToFirst()) { 
        while(cursor.moveToNext()) {
            for (int i = 0; i < colCount; i ++) { 
                Log.d(TAG, "## >> " + cursor.getString(i));
            }
            Log.d(TAG, "---------------");
        }
    }   
}
hovanessyan
  • 30,580
  • 6
  • 55
  • 83