Showing posts with label SMS content. Show all posts
Showing posts with label SMS content. Show all posts

Monday, October 14, 2013

Incoming SMS details

Using Android API's user can read incoming SMS message content programmatically.
To get SMS content first add below user permission in manifest file:
<uses-permission android:name="android.permission.READ_SMS"></uses-permission>

Then call below method from activity class:

public StringBuffer getIncomingSMSContent() {

ContentResolver contentResolver = getContentResolver();
Uri uri = Uri.parse("content://sms/inbox/");
StringBuffer messagedata = new StringBuffer();
int count = 0;
Cursor cursor = contentResolver.query(uri, null, null, null, null);
if (cursor.getCount() != 0) {
if (cursor.moveToFirst()) {
do {
messagedata.append("Incoming message count: " + (count +1) + "\n");
for (int m = 0; m < cursor.getColumnCount(); m++) {
if (cursor.getColumnName(m).equalsIgnoreCase("address")
|| cursor.getColumnName(m).equalsIgnoreCase("date")
|| cursor.getColumnName(m).equalsIgnoreCase("body")
|| cursor.getColumnName(m).equalsIgnoreCase("type"))
{
messagedata.append(cursor.getColumnName(m) + "  : "
+ cursor.getString(m));
messagedata.append("\n");
}
}
messagedata.append("\n");
count++;
} while (cursor.moveToNext());
}
}
cursor.close();
cursor = null;
return messagedata;
}

This method will return list of all incoming message content from inbox.

Here is the result :


In above result screen, 
address : mobile number from which device received message
date : message received time in milliseconds
type : message type incoming/outgoing. Type 1 indicates as incoming message type
body : message text