android中使用contentResolver捕获彩信的问题
我正在创建一个应用程序,它将检测何时发送或接收彩信,并捕获内容。我是通过使用contentResolver来执行此操作的”content://mms-sms/conversations". 当这个被触发时,我遍历对话以找到最后一个(刚刚发送的)。因为“content://mms-sms/conversations为所有设备设置光标时不起作用,我正在使用content://mms-sms/conversations?simple=true". 我迭代,找到列表中的第一个对话(列表按date desc排序),然后使用contentResolver.query(uri,uri.Parse()content://mms/part,selectionPart,空,空);但是,当我尝试使用此光标进行迭代时,找不到对话id的记录。我只是尝试检测何时发送或接收彩信,并获取相关信息。我已经看到了许多关于此的主题,但似乎没有任何解决问题的方法。有什么想法吗?谢谢android中使用contentResolver捕获彩信的问题,android,mms,android-contentresolver,android-cursor,Android,Mms,Android Contentresolver,Android Cursor,我正在创建一个应用程序,它将检测何时发送或接收彩信,并捕获内容。我是通过使用contentResolver来执行此操作的”content://mms-sms/conversations". 当这个被触发时,我遍历对话以找到最后一个(刚刚发送的)。因为“content://mms-sms/conversations为所有设备设置光标时不起作用,我正在使用content://mms-sms/conversations?simple=true". 我迭代,找到列表中的第一个对话(列表按date des
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);
}
请不要引用我的话,但我认为返回的_id是对话查询中的线程id。我成功使用的(对于MMS)是事务id,它应该作为tru id可用 可能还有其他解决方案,但如果您有tr_id,则可以查询content://mms/ 使用该tr_id,提取零件id(_id),然后查询“content://mms/part“+\u id 在查询mms部件表时,请记住可能有多条记录 返回,因此您需要逐步完成零件光标检查的全部内容 所需记录的类型