Read/Receive mms in my app

Can someone please give some code for receiving mms in app?

Answers

  • YkshLeoYkshLeo USMember ✭✭✭✭
    edited September 2016

    MMSs are a little bit different. They can be built with different parts (text, audio, images, etc.);

    If you have the MMS id in the mmsId variable. We can get detailed information about this MMS by using the content://mms/ provider:

    Uri uri = Uri.parse("content://mms/");
    String selection = "_id = " + mmsId;
    Cursor cursor = getContentResolver().query(uri, null, selection, null, null);
    

    To read text content from MMS :

    String selectionPart = "mid=" + mmsId;
                Android.Net.Uri uri = Android.Net.Uri.parse("content://mms/part");
                Android.Database.ICursor cursor = ContentResolver.Query(uri, null,
                    selectionPart, null, null);
                if (cursor.MoveToFirst())
                {
                    do
                    {
                        String partId = cursor.GetString(cursor.GetColumnIndex("_id"));
                        String type = cursor.GetString(cursor.GetColumnIndex("ct"));
                        if ("text/plain".Equals(type))
                        {
                            String data = cursor.GetString(cursor.GetColumnIndex("_data"));
                            String body;
                            if (data != null)
                            {
                                // implementation of this method below
                                body = GetMmsText(partId);
                            }
                            else
                            {
                                body = cursor.GetString(cursor.GetColumnIndex("text"));
                            }
                        }
                    } while (cursor.MoveToNext());
                }
    
    
    private string getMmsText(String id)
            {
                Android.Net.Uri partURI = Android.Net.Uri.Parse("content://mms/part/" + id);
                Stream inputStream = null;
                Java.Lang.StringBuilder sb = new Java.Lang.StringBuilder();
                try
                {
                    inputStream = ContentResolver.OpenInputStream(partURI);
                    if (inputStream != null)
                    {
                        Java.IO.InputStreamReader isr = new Java.IO.InputStreamReader(inputStream, "UTF-8");
                        Java.IO.BufferedReader reader = new Java.IO.BufferedReader(isr);
                        string temp = reader.ReadLine();
                        while (temp != null)
                        {
                            sb.Append(temp);
                            temp = reader.ReadLine();
                        }
                    }
                }
                catch (IOException e) { }
                finally
                {
                    if (inputStream != null)
                    {
                        try
                        {
                            inputStream.Close();
                        }
                        catch (IOException e) { }
                    }
                }
                return sb.ToString();
            }
    

    Refer :

  • SabaSoomroSabaSoomro USMember ✭✭

    Oh that looks Great (y) thanks a lot for replaying, I will try this and will let you know how it worked.

  • SabaSoomroSabaSoomro USMember ✭✭

    @YkshLeo what is the mmsId?

Sign In or Register to comment.