2013-08-05 2 views
0

mms 메시지를 보내고받을 때이를 감지하고 내용을 캡처 할 앱을 만듭니다. "content : // mms-sms/conversations"에 contentResolver를 사용하여이 작업을 수행하고 있습니다. 이것이 트리거되면 마지막 회신 (방금 보낸)을 찾기 위해 대화를 반복합니다. 모든 장치에 대해 커서를 설정할 때 "content : // mms-sms/conversations"가 작동하지 않았기 때문에 "content : // mms-sms/conversations? simple = true"를 사용하고 있습니다. 목록에서 첫 번째 대화를 찾은 다음 목록에서 date desc로 정렬 한 다음 contentResolver.query (uri, Uri.Parse ("content : // mms/part")를 사용하여 실제 내용을 가져 오기 위해 _id를 전달합니다. , selectionPart, null, null); 그러나이 커서를 사용하여 반복 할 때 대화 ID에 대한 레코드가 없습니다. 단순히 mms 보내거나받은 및 정보를 얻을 때 검색하려고 오전. 이에 다양한 주제를 본 적이 있지만 아무것도 문제를 해결하는 것 같았다 없다. 어떤 아이디어? 감사contentResolver를 사용하여 android에서 캡처하는 mms 관련 문제

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); 
} 

답변

0

이 날을 인용하지만 반환되는 _id가 대화 쿼리에서 thread_id 생각하지 마십시오. 무엇을 내가 성공했다면 (for MMS) tr_id로 사용할 수있는 트랜잭션 ID입니다.

다른 솔루션이있을 수도 있지만 tr_id를 사용하여 content : // mms/ 에 해당 tr_id를 쿼리하고 부품 ID (_id)를 추출한 다음 "content : // mms/part"+ _id를 쿼리 할 수 ​​있습니다.

mms 파트 테이블에 대한 쿼리에서 복수 레코드 이 반환되므로 부품 커서의 전체 내용을 단계별로 수행하여 원하는 레코드 유형을 확인해야한다는 점을 명심하십시오.

관련 문제