Reputation: 327
I am creating an app that will detect when a mms message is sent or received and will capture the contents. I am doing this by using a contentResolver to "content://mms-sms/conversations". When this is triggered, I iterate through the conversations to find the last one (just sent). Because "content://mms-sms/conversations" did not work when setting my cursor for all devices, I am using "content://mms-sms/conversations?simple=true". I iterate, find the first conversation in the list (the list is ordered by date desc), then pass the _id to get the actual contents, using contentResolver.query(uri, Uri.Parse("content://mms/part", selectionPart, null, null); However, when I try to iterate using this cursor, no records are found for the conversation id. I am simply trying to detect when an mms is send or received and get the info on it. I've seen numerous topics on this but nothing has seemed to resolve the issue. Any ideas? Thanks
public void getMMS(Context context)
{
SentinelService.grabbingMMS = false;
boolean sent, startup;
final String[] projection = new String[] { "*" };
Uri uri = Uri.parse("content://mms-sms/conversations?simple=true");
Cursor cursor = contentResolver.query(uri, null, null, null, "_date DESC");
if (cursor.moveToFirst()) {
do
{
String id = cursor.getString(cursor.getColumnIndex("_id"));
String d = cursor.getString(cursor.getColumnIndex("date"));
MMSLog mmsLog = buildMMSLog(id, sent);
} while (cursor.moveToNext());
}
private MMSLog buildMMSLog(String mmsID, boolean sent)
{
String body = "", partID = "", imageString = null, type = "", tempType = "", selectionPart = "mid=" + mmsID;
Bitmap bitmap = null;
Uri uri = Uri.parse(MMS_PART);
Cursor cursor = contentResolver.query(uri, null, selectionPart, null,
null);
if (!cursor.isAfterLast()) {
String[] s = cursor.getColumnNames();
partID = cursor.getString(cursor.getColumnIndex("_id"));
tempType = cursor.getString(cursor.getColumnIndex("ct"));
if ("text/plain".equals(tempType)) {
String data = cursor.getString(cursor.getColumnIndex("_data"));
if (data != null) {
body = getMMSText(partID);
} else {
body = cursor.getString(cursor.getColumnIndex("text"));
}
} else if ("image/jpg".equals(tempType)
|| "image/gif".equals(tempType)
|| "image/jpeg".equals(tempType)
|| "image/bmp".equals(tempType)
|| "image/png".equals(tempType)) {
bitmap = getMMSImage(partID);
type = tempType;
}
}
try {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 50, stream);
bitmap.recycle();
byte[] byteArray = stream.toByteArray();
stream = new ByteArrayOutputStream();
imageString = new String(Base64.encodeBase64(byteArray));
}
catch (Exception ex) {
}
return new MMSLog(getAddressNumber(mmsID, sent), body, imageString,
type, sent);
}
Upvotes: 0
Views: 853
Reputation: 500
Don't quote me on this but I think the _id that is returned is the thread_id from the conversations query. What I have had success with (for MMS) is the transaction id which should be available as tr_id.
There may be other solutions but given the tr_id you can then query content://mms/ with that tr_id, extract the part id (_id) and then query "content://mms/part" + _id.
In your query of the mms part table keep in mind that there maybe multiple records returned so you need to step through the entire contents of the part cursor checking the types for the record you want.
Upvotes: 0