Get attachment from unread MMS messages

前端 未结 2 1717
无人及你
无人及你 2021-02-11 02:38

I would like to get attachment from unread MMS messages, but the codes I have doesn\'t allow me to do so. How do I go about doing that?

Codes modified f

相关标签:
2条回答
  • 2021-02-11 02:59

    Figured out myself, the codes are as follows:

    private void checkMMSMessages() {
    
        String[] columns = null; 
        String[] values = null;
        String read = "read = 0";
    
        Cursor curPdu = getContentResolver().query(Uri.parse("content://mms"), null, read, null, null); 
        if(curPdu.moveToNext()){
            String id = curPdu.getString(curPdu.getColumnIndex("_id"));
            Cursor curPart = getContentResolver().query(Uri.parse ("content://mms/" + id + "/part"), null, null, null, null);
    
            while(curPart.moveToNext()) 
            { 
                columns = curPart.getColumnNames(); 
                if(values == null) 
                    values = new String[columns.length]; 
    
                for(int i=0; i< curPart.getColumnCount(); i++){ 
                    values[i] = curPart.getString(i); 
                } 
    
                if(values[3].equals("image/jpeg") || values[3].equals("image/bmp") || 
                        values[3].equals("image/gif") || values[3].equals("image/jpg") ||
                        values[3].equals("image/png")) 
                { 
                    GetMmsAttachment(values[0],values[12]); 
                } 
            } 
        }
    }
    
    private void GetMmsAttachment(String _id, String _data) 
    { 
        Uri partURI = Uri.parse("content://mms/part/" + _id ); 
        String filePath = "/sdcard/photo.jpg";
        InputStream is = null;
        OutputStream picFile = null;
        Bitmap bitmap = null;
    
        try { 
            is = getContentResolver().openInputStream(partURI); 
            bitmap = BitmapFactory.decodeStream(is);
    
            picFile = new FileOutputStream(filePath);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 50, picFile);
            picFile.flush();
            picFile.close();
        } 
        catch (Exception e) 
        { 
            e.printStackTrace(); 
            //throw new MmsException(e); 
        } 
    }
    
    0 讨论(0)
  • 2021-02-11 03:05

    I think he asked how to retrieve the attachment from the server, as it is written UNREAD mms... If you have the column ct_l how to get the data from that internet address?

    0 讨论(0)
提交回复
热议问题