Note that there are some explanatory texts on larger screens.

plurals
  1. POGet attachment from unread MMS messages
    primarykey
    data
    text
    <p>I would like to get attachment from <strong>unread</strong> MMS messages, but the codes I have doesn't allow me to do so. How do I go about doing that?</p> <p>Codes modified from <a href="http://www.anddev.org/multimedia-problems-f28/acces-to-the-mms-part-file-content-t10433.html#p42667" rel="nofollow">here</a>:</p> <pre><code>private void checkMMSMessages(){ // Create string arrays to store the queries later on String[] columns = null; String[] values = null; // Calls the ContentResolver to query for columns with URI "content:mms" Cursor curPdu = getContentResolver().query(Uri.parse("content://mms"), null, null, null, null); if(curPdu.moveToNext()){ //String read = curRead.getString(curRead.getColumnIndex("read")); // Gets ID of message String id = curPdu.getString(curPdu.getColumnIndex("_id")); // Gets thread ID of message String thread_id = curPdu.getString(curPdu.getColumnIndex("thread_id")); // Gets subject of message (if any) String subject = curPdu.getString(curPdu.getColumnIndex("sub")); // Gets date of message String date = curPdu.getString(curPdu.getColumnIndex("date")); String selectionAddr = new String ("msg_id = '" + id + "'"); Uri uriAddr = Uri.parse ("content://mms/" + id + "/addr"); Cursor curAddr = getContentResolver().query(uriAddr, null, null, null, null); if(curAddr.moveToNext()){ String contact_id = curAddr.getString (curAddr.getColumnIndex ("contact_id")); String address = curAddr.getString (curAddr.getColumnIndex ("address")); String selectionPart = new String ("mid = '" + id + "'"); Cursor curPart = getContentResolver ().query(Uri.parse ("content://mms/part"), null, null, null, null); //Cursor curPart = context.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&lt; curPart.getColumnCount(); i++){ values[i] = curPart.getString(i); } String contact_idd = curPart.getString(0); 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]); //Toast.makeText(getApplicationContext(), "Retrieved MMS attachment", Toast.LENGTH_LONG); } } } } } 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, 100, picFile); picFile.flush(); picFile.close(); } catch (Exception e) { e.printStackTrace(); //throw new MmsException(e); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload