2

I am able to read mms image from device using query "content://mms/part" and sending those mmsimages to server , but my requirement is in my application i will read all the mms images from device and backup to server from the second time when app is opened i need to backup only latest mms to the server , for this requirment i need to read the mms from the device after particular date given by me . is it possible?

 Cursor curPart = getContentResolver (). query (Uri.parse ("content://mms/part"), null,    null, null, null);


 while(curPart.moveToNext())
      {
      coloumns = curPart.getColumnNames();

      for(int i=0;i<coloumns.length;i++)
      {
          Log.e("coloumns",coloumns[i]);

      }
        if(values == null)
        values = new String[coloumns.length];

        for(int i=0; i< curPart.getColumnCount(); i++)
        {
        values[i] = curPart.getString(i);
        }

            if(values[3].equals("image/jpeg"))
            {
                                mms_image.add(GetMmsAttachment(values[0],values[12],values[4]));
            }



    }




        private String GetMmsAttachment(String _id, String _data,String fileName )
    {

    Uri partURI = Uri.parse("content://mms/part/" + _id );
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    InputStream is = null;

    try {
    is = getContentResolver().openInputStream(partURI);

    convertBitmapToFile(bitmap);


    byte[] buffer = new byte[256];
    int len = is.read(buffer);
    while (len >= 0) {
    baos.write(buffer, 0, len);
    len = is.read(buffer);
    }
    }
    catch (IOException e)
    {
    e.printStackTrace();
    //throw new MmsException(e);
    }
    finally
    {
    if (is != null)
    {
    try
    {
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    //writeToFile(bais,"data/",fileName);
    is.close();
    bais.close();
    }
    catch (IOException e)
    {`enter code here`
    e.printStackTrace();
    }
    }
    }
    return strMyImagePath;
    }
  • definitely possible - take a look at the "how to get data from a SMS" section of http://stackoverflow.com/a/6446831/1542000 which describes how to get a date from a SMS or MMS, you can then convert the date string into a time object (http://stackoverflow.com/questions/2742380/how-to-convert-string-date-to-timestamp-in-java) for comparing / determining which MMS images need to be sent to the server. – cronburg Dec 19 '13 at 07:26
  • there is no how to get the date for mms in the link u refered me and there is no date coloumn in content://mms/part/ @KarlC – sudheer kumar Dec 19 '13 at 10:24
  • the "How to get data from a SMS" applies equally well to MMS messages (which gives you a date). You have the message ID in your code already, so all you need to do is change "content://sms" to "content://mms" – cronburg Dec 19 '13 at 16:56

1 Answers1

0

This is the code I was talking about in my comment (from How to Read MMS Data in Android?):

String selection = "_id = "+_id;
Uri uri = Uri.parse("content://mms");
Cursor cursor = contentResolver.query(uri, null, selection, null, null);
String phone = cursor.getString(cursor.getColumnIndex("address"));
int type = cursor.getInt(cursor.getColumnIndex("type"));// 2 = sent, etc.
String date = cursor.getString(cursor.getColumnIndex("date"));
String body = cursor.getString(cursor.getColumnIndex("body"));

You can then compare the date against your given date to determine whether or not you want to upload data corresponding to the current _id.

Community
  • 1
  • 1
cronburg
  • 892
  • 1
  • 8
  • 24
  • while i am backuping latest sms to the server everytime i am saving current time in a string using shared preferences and getting only recent sms like shown below Uri uriSMSURI = Uri.parse("content://sms/"); where="date"+">"+final_msg_time; but when backuping mmsimage using query Uri uri = Uri.parse("content://mms/part"); there is no date coloumn to compare in this cursor @Karlc – sudheer kumar Dec 20 '13 at 11:31
  • @sudheerkumar - try actually reading / using the code I gave you - you're comment refers to `Uri.parse("content://mms/part");` but the code I gave uses `Uri.parse("content://mms");` to get the date column. – cronburg Dec 21 '13 at 05:05
  • AFAIK the difference is that "mms/part" is the multimedia data table whereas "mms" is a table containing metadata. – cronburg Dec 21 '13 at 05:07
  • I need to backup multimedia mms image to the server not meta data – sudheer kumar Jan 02 '14 at 11:36
  • Exactly, and the "date" of a message is meta data. You get the mms image from `"content://mms/part"` and you get the *corresponding* date (of the message in which the image was sent) from `"content://mms"`. – cronburg Jan 02 '14 at 15:15