0

How can I retrieve the SMS logs? I just want to be able to grab a list of the Contacts that most recently were sent SMS messages by the phone or received by the phone.

I found CallLogs object but I suspect this only works for phone calls... please correct me if I'm wrong.

http://www.dcpagesapps.com/developer-resources/android/25-android-tutorial-call-logs

http://developer.android.com/reference/android/provider/CallLog.Calls.html

I found this, but I was wondering if there is a better way....

Android 1.5: Reading SMS messages

Community
  • 1
  • 1
ycomp
  • 8,316
  • 19
  • 57
  • 95

2 Answers2

1

This is my way of getting the SMS and it works great. There are separate logs for sent and received. Certain third party SMS program messages might not show up. It looks for SMS sent or received from a number in a string called phoneNumbers and adds all the found SMS messages in to an array for processing.

public void getSMS(){

final String[] projection = null;
final String selection = "address IN (" + phoneNumbers + ")";
final String selectionArgs[] = null;
final String sortOrder = null;
Cursor c = null;

c = getContentResolver().query(
Uri.parse("content://sms/sent"),
projection,
 selection,
 selectionArgs,
 sortOrder);

if (c.moveToFirst() && c.isNull(c.getColumnIndex("date"))==false && c.isNull(c.getColumnIndex("address"))==false) {

do {

CCall call = new CCall(c.getLong(c.getColumnIndex("date")),c.getString(c.getColumnIndex("address")),4,0);
arrCall.add(call);

} while (c.moveToNext()); 


    }

c = getContentResolver().query(
Uri.parse("content://sms/inbox"),
projection,
selection,
selectionArgs,
sortOrder);

if (c.moveToFirst() &&  c.isNull(c.getColumnIndex("date"))==false && c.isNull(c.getColumnIndex("address"))==false) {

do {

CCall call = new CCall(c.getLong(c.getColumnIndex("date")),c.getString(c.getColumnIndex("address")),5,0);

arrCall.add(call);

 } while (c.moveToNext()); 

}

c.close();

}
Urban
  • 76
  • 4
0

Sorry, but there is nothing in the Android SDK related to "SMS logs".

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491