First, I would listen to the incoming SMS, and there was a notification on the incoming SMS. Then, if the user opens your application, update it using this to get the data you need:
Uri allMessage = Uri.parse("content://sms/inbox"); ContentResolver cr = getContentResolver(); Cursor c = cr.query(allMessage, null, null, null, null); //shows one message c.moveToNext(); //uncomment to cycle thru ALL messages... This will take AWHILE //while (c.moveToNext()) { for(int i = 0; i != c.getColumnCount(); i++){ String columnName = c.getColumnName(i); String columnValue = c.getString(i); Log.v(TAG, "Col: " + columnName); Log.v(TAG, "Val: " + columnValue); } //}
Play with him a little. It should have all the necessary data (distinguish SMS messages by timestamp)
source share