I want to read MMS data I have seen the part table in the mmssms.db where the mms entries are stored; I am using a cursor and I want to know the appropriate
I had to make some modifications in order to get this to work for me.
When I retrieve the cursor.getString(cursor.getColumnIndex("type")) from the mms-sms/conversations content, ("content://mms-sms/conversations/") I test the value of the "type" field for null. If the variable is null - i.e.
String otype = c.getString(c.getColumnIndex("type"));
if(otype != null) {
//this is an sms - handle it...
the message is an SMS, else it is an MMS. For MMS's you have to test for both mime types as follows:-
if (("application/vnd.wap.multipart.related".equalsIgnoreCase(msg_type)
||"application/vnd.wap.multipart.mixed".equalsIgnoreCase(msg_type))
&& !id.equalsIgnoreCase(lastMMSID)) {
//this is a MMS - handle it...
The only way that I could find that works pretty well to differentiate between inbound and outbound MMS's, is to test the null status of the "m_id" field of the mms-sms/conversations content.
String m_id = c.getString(c.getColumnIndex("m_id"));
String mDirection = m_id == null? "OUT": "IN";
A final thought on how to get the Address Field. For some reason the Address Content does not like to be queried with a {" * "} parameter, but this works:-
final String[] projection = new String[] {"address", "contact_id", "charset", "type"};
If it is an outbound message, the "type" to look for will be 151. For an inbound message, the "type" will be 137. A fully functional piece of code will look something like this:-
private String getANumber(int id) {
String add = "";
final String[] projection = new String[] {"address","contact_id","charset","type"};
final String selection = "type=137 or type=151"; // PduHeaders
Uri.Builder builder = Uri.parse("content://mms").buildUpon();
builder.appendPath(String.valueOf(id)).appendPath("addr");
Cursor cursor = context.getContentResolver().query(
builder.build(),
projection,
selection,
null, null);
if (cursor.moveToFirst()) {
do {
String add = cursor.getString(cursor.getColumnIndex("address"));
String type: cursor.getString(cursor.getColumnIndex("type"));
} while(cursor.moveToNext());
}
// Outbound messages address type=137 and the value will be 'insert-address-token'
// Outbound messages address type=151 and the value will be the address
// Additional checking can be done here to return the correct address.
return add;
}
To all the brave warriors who have gone before me in this post - I thank thee from the bottom of my heart!