2017-04-16 45 views
1

我正在開發一個適用於android的SMS-MMS電子倉庫應用程序。其目的是糾正Android中存在的一些漏洞,並在特定聯繫人(加密的SMS和MMS)之間創建「安全」通信空間。解析接收的圖像和文本的彩信

我已經實現了所有的功能,除了接收MMS的功能。我沒有找到關於此事的文件。我一直在閱讀了很多從實現這個功能,他們都等待股票應用程序接收彩信,然後檢索它,這是不是我要找的,我的應用程序,就是要其他應用程序代碼默認的一個。

所以,在這裏迴避我的問題:

接收彩信的意圖,我該如何解析圖像和文本之後?

回答

0

所以,你能做些什麼來獲取圖片是去我得到了MMS的id和經歷(「內容:// MMS /部」) 做類型檢查:

String type = cursor.getString(cursor.getColumnIndex("ct")); 
String partId = cursor.getString(cursor.getColumnIndex("_id")); 


//is type a picture 
if ("image/jpeg".equals(type) || "image/bmp".equals(type) 
    || "image/gif".equals(type) || "image/jpg".equals(type) 
    || "image/png".equals(type)) { 
        getMmsImage(partId); // load in your picture 
     } 

現在你,你讓你知道圖片的位置的部件ID,所以你可以使用你想要比如什麼,如果你只是希望它加載它作爲一個位圖,你可以這樣做:

public Bitmap getMmsImage(String _id, Context context) { 

     Uri partURI = Uri.parse("content://mms/part/" + _id); 
     InputStream is = null; 
     Bitmap bitmap = null; 
     try { 
      is = context.getContentResolver().openInputStream(partURI); 
      bitmap = BitmapFactory.decodeStream(is); 

     } catch (Exception e) {// probably should do an ioException around here} 
     finally { 
      if (is != null) { 
       try { 
        is.close(); 
       } catch (IOException e) {} 
      } 
     } 
     return bitmap; 
    } 

現在我想指出的是,如果你想要動畫GIF這不會工作,它會加載的GIF,但他們仍然是我法師。如果你想讓它們動起來,你可以使用類似Glide的東西,併爲它指定uri的路徑位置。滑翔需要一段時間才能加載gif,只是公平的警告。

至於接收彩信時,你總是可以使用觀察和負載所增加的消息在每當觀察者說有變化......或者,如果你希望它是默認的信使使用廣播接收器。