【问题标题】:Problems with mms capturing in android using contentResolver使用 contentResolver 在 android 中捕获 mms 的问题
【发布时间】:2013-10-05 08:03:57
【问题描述】:

我正在创建一个应用程序,该应用程序将检测何时发送或接收彩信并捕获内容。我通过将 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);
}

【问题讨论】:

    标签: android mms android-contentresolver android-cursor


    【解决方案1】:

    不要引用我的话,但我认为返回的 _id 是对话查询中的 thread_id。我取得的成功(对于 MMS)是事务 id,它应该可以作为 tr_id 使用。

    可能还有其他解决方案,但鉴于 tr_id 您可以查询 content://mms/ 使用该 tr_id,提取部件 id (_id),然后查询“content://mms/part”+_id。

    在您对 mms 零件表的查询中,请记住可能有多个记录 返回,因此您需要逐步检查部分光标检查的全部内容 您想要的记录类型。

    【讨论】:

      猜你喜欢
      • 2011-08-31
      • 1970-01-01
      • 1970-01-01
      • 2012-01-23
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多