所以,你能做些什麼來獲取圖片是去我得到了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,只是公平的警告。
至於接收彩信時,你總是可以使用觀察和負載所增加的消息在每當觀察者說有變化......或者,如果你希望它是默認的信使使用廣播接收器。