2014-01-30 31 views
0

我確實收到了關於如何檢索從此鏈接發送的mms文本和圖像的信息:How to Read MMS Data in Android?如何從content:// mms中檢索mms的日期。

但我不知道如何檢索發送的mms的日期。

我知道我必須看看content:// mms而不是content:// mms/part。

這是評判檢索彩信的文字:

private String getMmsText(String id) { 
     Uri partURI = Uri.parse("content://mms/part/" + id); 
     InputStream is = null; 
     StringBuilder sb = new StringBuilder(); 
     try { 
      is = getContentResolver().openInputStream(partURI); 
      if (is != null) { 
       InputStreamReader isr = new InputStreamReader(is, "UTF-8"); 
       BufferedReader reader = new BufferedReader(isr); 
       String temp = reader.readLine(); 
       while (temp != null) { 
        sb.append(temp); 
        temp = reader.readLine(); 
       } 
      } 
     } catch (IOException e) { 
     } finally { 
      if (is != null) { 
       try { 
        is.close(); 
       } catch (IOException e) { 
       } 
      } 
     } 
     return sb.toString(); 
    } 

,然後在onCreate方法,我用這個代碼來獲取信息:

Cursor cursor = getContentResolver().query(uri, null, selectionPart, 
       null, null); 
     if (cursor.moveToFirst()) { 
      do { 
       String partId = cursor.getString(cursor.getColumnIndex("_id")); 
       String type = cursor.getString(cursor.getColumnIndex("ct")); 
       if ("text/plain".equals(type)) { 
        String data = cursor.getString(cursor 
          .getColumnIndex("_data")); 

        if (data != null) { 
         // implementation of this method above 
         body = getMmsText(partId); 
        } else { 
         body = cursor.getString(cursor.getColumnIndex("text")); 
        } 
       } 
      } while (cursor.moveToNext()); 
     } 

     try { 


      main.setText(body); 
      img.setImageBitmap(bitmap); 
     } catch (Exception e) { 

      e.printStackTrace(); 
     } 

我只是想知道我可以在哪裏進行更改以獲取日期值。

有些信息會非常有幫助。

回答

3

我不是太熟悉MMS的,但我想像這樣的事情就至少得拿到你開始

Cursor cursor = activity.getContentResolver().query(Uri.parse("content://mms"),null,null,null,date DESC); 
count = cursor.getCount(); 
if (count > 0) 
{ 
    cursor.moveToFirst(); 
    long timestamp = cursor.getLong(2); 
    Date date = new Date(timestamp); 
    String subject = cursor.getString(3); 
} 

這是沒有經過充分測試的課程,但應該指向你在正確的方向。希望這可以幫助!

編輯 做了一些的讀出之後,曾經是(可能仍然是)一個「錯誤」,在MMS消息中的時間戳,檢索數據時。如果你最終得到一個愚蠢的價值(如時代),那麼在使用它之前,你必須* 1000。只是旁邊:) I.e .:

long timestamp = (cursor.getLong(2) * 1000); 
+0

感謝信息。這真的很有幫助.. :)。該代碼正在工作,但由於某種原因,該年顯示爲1970年。 – mike20132013

+1

啊。查看我的編輯:)只需更改爲:long timestamp =(cursor.getLong(2)* 1000); - 應該整理:) – LokiSinclair

+0

perfect..its working .. :) – mike20132013