I am working on a android application which read the sms from content provider. The application works fine and read sms fine from content provider. But sometime (very rare) the 'address' column returns null for the sms message.
Here is sample code What I am using:
String whereClause = "_id > " + String.valueOf(Database.getLastSmsId(this));
Cursor cursor = getContentResolver().query(smsUri, null, whereClause, null, null);
if(cursor.moveToFirst()) {
do {
int id = cursor.getInt(cursor.getColumnIndex("_id"));
String protocol = cursor.getString(cursor.getColumnIndex("protocol"));
String body = cursor.getString(cursor.getColumnIndex("body"));
String address = cursor.getString(cursor.getColumnIndex("address")); // <----- Here is the problem
// address returns as null string
String date = cursor.getString(cursor.getColumnIndex("date"));
Log.d(Constants.TAG, "SMS event received. address="+address);
} while(cursor.moveToNext());
}
I am getting this issue on Motorola Driod Android v2.3.5. Please advise.
Ali
I found the problem. The android OS save the message as draft in SMS content provider, if start writing and then close the SMS app (due to incoming call or any other reason). This generate a new entry in SMS database with null value in 'address' column.
Salman