我正在创建一个应用程序,它将检测何时发送或接收彩信并捕获内容。我通过将 contentResolver 用于“content://mms-sms/conversations”来做到这一点。当这被触发时,我遍历对话以找到最后一个(刚刚发送)。因为在为所有设备设置光标时“content://mms-sms/conversations”不起作用,所以我使用的是“content://mms-sms/conversations?simple=true”。我迭代,在列表中找到第一个对话(列表按日期 desc 排序),然后传递 _id 以获取实际内容,使用 contentResolver.query(uri, Uri.Parse("content://mms/part" , selectionPart, null, null); 但是,当我尝试使用此游标进行迭代时,找不到对话 id 的记录。我只是想检测何时发送或接收彩信并获取有关信息。我已经看到了很多关于此的主题,但似乎没有任何东西可以解决这个问题。有任何想法吗?谢谢
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);
}