Acces to the MMS part file content

All your problems with Audio, Video and Images.

Acces to the MMS part file content

Postby gynoid » Tue Jan 19, 2010 12:21 pm

Hi,

I list all the MMS with the method Activity.managedQuery() and the following URI : "content://mms".

I would like to access to the MMS part file. So, I used the following URI : "content://mms/part". I've got the list of all the MMS part files but I'm not able to access to the files content. I tried these methods and I always got an exception :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. File file = new File(cursor.getString("_data"));// this field contains a value like /data/data/com.android.providers.telephony/app_parts/PART_1263130844804 which is the path of the part file
  3.  
  4.  
  5.  
  6. // 1st method
  7.  
  8. new FileInputStream(file);// FileNotFoundException
  9.  
  10.  
  11.  
  12. // 2nd method
  13.  
  14. context.openFileInput(file.getPath());// IllegalArgumentException : File contains a path separator
  15.  
  16.  
  17.  
  18. // 3th method
  19.  
  20. context.getContentResolver().openInputStream(Uri.parse(file.getPath()));// FileNotFoundException : No content provider
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


How can I access to the content of these part files ?
Thx,
gynoid
Freshman
Freshman
 
Posts: 3
Joined: Tue Jan 19, 2010 12:12 pm

Top

Postby Flairy » Wed Jan 20, 2010 12:10 am

I have found this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.      Uri partURI = Uri.parse("content://mms/part/" + partId);
  3.  
  4.      ByteArrayOutputStream baos = new ByteArrayOutputStream();
  5.  
  6.      InputStream is = null;
  7.  
  8.  
  9.  
  10.      try {
  11.  
  12.           is = mContentResolver.openInputStream(partURI);
  13.  
  14.  
  15.  
  16.           byte[] buffer = new byte[256];
  17.  
  18.           int len = is.read(buffer);
  19.  
  20.           while (len >= 0) {
  21.  
  22.                baos.write(buffer, 0, len);
  23.  
  24.                len = is.read(buffer);
  25.  
  26.           }
  27.  
  28.      } catch (IOException e) {
  29.  
  30.           Log.e(TAG, "Failed to load part data", e);
  31.  
  32.           c.close();
  33.  
  34.           throw new MmsException(e);
  35.  
  36.      } finally {
  37.  
  38.           if (is != null) {
  39.  
  40.              try {
  41.  
  42.                 is.close();
  43.  
  44.              } catch (IOException e) {
  45.  
  46.                 Log.e(TAG, "Failed to close stream", e);
  47.  
  48.              } // Ignore
  49.  
  50.           }
  51.  
  52.      }
  53.  
  54.  
  55.  
  56.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4

baos contains your part content...
Flairy
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Jan 19, 2010 11:52 pm

Postby gynoid » Wed Jan 20, 2010 1:45 am

Thank you Flairy for your help !

I've just found the same code. ;) In fact, it seems that all columns named "_data" in content providers should be accessed by this way.
gynoid
Freshman
Freshman
 
Posts: 3
Joined: Tue Jan 19, 2010 12:12 pm

Tnks a lot

Postby incubus » Tue Jan 26, 2010 4:34 pm

hey thnks, I was looking for this info for a week. I'm trying to access /data/data/com.android.providers.telephony/app_parts/PART_* files via ftp, I'm not sure if it is going to work, that is the idea:

1. Enter into terminal emulator
2. su
3. chmod 777 /data/data/com.android.providers.telephony/app_parts/
4. Connect via siwFTP (it creates a server in android)
5. Download all PART FILES
6. Run Flairy's script in local machine
7. There is an issue, how to know parts extension? well on this thread there is a good info about that
http://forum.xda-developers.com/archive ... 52510.html
"sqlite3 -header /data/data/com.android.providers.telephony/databases/mmssms.db "SELECT _data, ct FROM part;"
The first column is the full path to the file, and the 2nd column is the mime type of the file" (JesusFreke Nov-30-2008)

8. Any suggestion, have you try something like that?.

Regards
incubus
Freshman
Freshman
 
Posts: 2
Joined: Tue Jan 26, 2010 3:38 pm

Hi, something intersting

Postby incubus » Wed Jan 27, 2010 3:25 pm

I did my test and the results are:

1. chmod 777 works fine, but when a new mms arrive it has no permissions, so access from ftp gave me access error on new mms message. chmod 777 just work if you give permission to the exactly folder, chmod -R 777 wont work, so the correct way is chmod 777 /data/data/com.android.providers.telephony/app_parts/* . chmod is not a clean way to access files because it can gave you a security problem, the best way is copy those files to sdcard. I will tell you how in point 5.

2. FTP works fine, when a file has permission it can be downloaded by ftp.

3. When the PART file is opened on local machine it can be viewed without problem, for example if you have a PART_5353536363 file and that file is an image it can be opened (with mozilla for example).

4. I didn't test Flairy's script.

5. FTP can works fine if you copy PART_* files to sdcard with adb, for example
adb -s DEVICE_SERIAL_NUMBER shell cp /data/data/com.android.providers.telephony/app_parts/* /sdcard/mmsFolder

so when you open the ftp (swiFTP) in some explorer the sdcard files can be downloaded, and then get access to the files.

Next steps:

1. I will try to create an script that review evry time that a new mms image is donwloaded, and then transfer the new files to the computer, with adb and ftp.

2. I will try to create an app that replace the script, so it will be running on android, and when a new mms image is downloade the app automatically transfer the files to sdcard, delete mms from thelephone, so a local machine can access the files without problem.


Sorry if there is a disorder in the ideas, sorry about english, jejeje my english is not good, but i try. the important language is the code.

Bye.
incubus
Freshman
Freshman
 
Posts: 2
Joined: Tue Jan 26, 2010 3:38 pm

Access to the MMS part file content

Postby alphaRiv » Thu May 06, 2010 2:31 pm

Me and my college found solution. Here is the code

private void checkMMSMessages(){
String[] coloumns = null;
String[] values = null;

Cursor curPdu = context.getContentResolver ().query(Uri.parse("content://mms"), null, null, null, null);
if(curPdu.moveToNext()){
String id = curPdu.getString (curPdu.getColumnIndex ("_id"));
String thread_id = curPdu.getString (curPdu.getColumnIndex ("thread_id"));
String subject = curPdu.getString (curPdu.getColumnIndex ("sub"));
String date = curPdu.getString (curPdu.getColumnIndex ("date"));

String selectionAddr = new String ("msg_id = '" + id + "'");
Uri uriAddr = Uri.parse ("content://mms/" + id + "/addr");
Cursor curAddr = context.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 = context.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())
{
coloumns = curPart.getColumnNames();
if(values == null)
values = new String[coloumns.length];

for(int i=0; i< curPart.getColumnCount(); i++){
values[i] = curPart.getString(i);
}
String contact_idd = curPart.getString (0);
if(values[3].equals("image/jpeg"))
{
GetMmsAttachment(values[0],values[12],values[4]);
}
}
}
}
}




private void GetMmsAttachment(String _id, String _data,String fileName )
{
Uri partURI = Uri.parse("content://mms/part/" + _id );
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream is = null;

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

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)
{
e.printStackTrace();
} // Ignore
}
}

}
alphaRiv
Once Poster
Once Poster
 
Posts: 1
Joined: Thu May 06, 2010 2:20 pm

Top

Postby Draffodx » Thu May 06, 2010 3:58 pm

Code wrapped :D

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private void checkMMSMessages(){
  2.  
  3. String[] coloumns = null;
  4.  
  5. String[] values = null;
  6.  
  7.  
  8.  
  9. Cursor curPdu = context.getContentResolver ().query(Uri.parse("content://mms"), null, null, null, null);
  10.  
  11. if(curPdu.moveToNext()){
  12.  
  13. String id = curPdu.getString (curPdu.getColumnIndex ("_id"));
  14.  
  15. String thread_id = curPdu.getString (curPdu.getColumnIndex ("thread_id"));
  16.  
  17. String subject = curPdu.getString (curPdu.getColumnIndex ("sub"));
  18.  
  19. String date = curPdu.getString (curPdu.getColumnIndex ("date"));
  20.  
  21.  
  22.  
  23. String selectionAddr = new String ("msg_id = '" + id + "'");
  24.  
  25. Uri uriAddr = Uri.parse ("content://mms/" + id + "/addr");
  26.  
  27. Cursor curAddr = context.getContentResolver ().query (uriAddr, null, null, null, null);
  28.  
  29. if(curAddr.moveToNext()){
  30.  
  31. String contact_id = curAddr.getString (curAddr.getColumnIndex ("contact_id"));
  32.  
  33. String address = curAddr.getString (curAddr.getColumnIndex ("address"));
  34.  
  35. String selectionPart = new String ("mid = '" + id + "'");
  36.  
  37. Cursor curPart = context.getContentResolver (). query (Uri.parse ("content://mms/part"), null, null, null, null);
  38.  
  39. //Cursor curPart = context.getContentResolver ().query(Uri.parse ("content://mms/" + id + "/part"), null, null, null, null);
  40.  
  41.  
  42.  
  43. while(curPart.moveToNext())
  44.  
  45. {
  46.  
  47. coloumns = curPart.getColumnNames();
  48.  
  49. if(values == null)
  50.  
  51. values = new String[coloumns.length];
  52.  
  53.  
  54.  
  55. for(int i=0; i< curPart.getColumnCount(); i++){
  56.  
  57. values[i] = curPart.getString(i);
  58.  
  59. }
  60.  
  61. String contact_idd = curPart.getString (0);
  62.  
  63. if(values[3].equals("image/jpeg"))
  64.  
  65. {
  66.  
  67. GetMmsAttachment(values[0],values[12],values[4]);
  68.  
  69. }
  70.  
  71. }
  72.  
  73. }
  74.  
  75. }
  76.  
  77. }
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. private void GetMmsAttachment(String _id, String _data,String fileName )
  88.  
  89. {
  90.  
  91. Uri partURI = Uri.parse("content://mms/part/" + _id );
  92.  
  93. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  94.  
  95. InputStream is = null;
  96.  
  97.  
  98.  
  99. try {
  100.  
  101. is = context.getContentResolver().openInputStream(partURI);
  102.  
  103.  
  104.  
  105. byte[] buffer = new byte[256];
  106.  
  107. int len = is.read(buffer);
  108.  
  109. while (len >= 0) {
  110.  
  111. baos.write(buffer, 0, len);
  112.  
  113. len = is.read(buffer);
  114.  
  115. }
  116.  
  117. }
  118.  
  119. catch (IOException e)
  120.  
  121. {
  122.  
  123. e.printStackTrace();
  124.  
  125. //throw new MmsException(e);
  126.  
  127. }
  128.  
  129. finally
  130.  
  131. {
  132.  
  133. if (is != null)
  134.  
  135. {
  136.  
  137. try
  138.  
  139. {
  140.  
  141. ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
  142.  
  143. //writeToFile(bais,"data/",fileName);
  144.  
  145. is.close();
  146.  
  147. bais.close();
  148.  
  149. }
  150.  
  151. catch (IOException e)
  152.  
  153. {
  154.  
  155. e.printStackTrace();
  156.  
  157. } // Ignore
  158.  
  159. }
  160.  
  161. }
  162.  
  163.  
  164.  
  165. }
Parsed in 0.045 seconds, using GeSHi 1.0.8.4
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Re: Acces to the MMS part file content

Postby Iqra » Sun Jun 17, 2012 3:20 pm

Guys i need your help..i want to read mms in android and then convert them in to a string or bytes. is it possible?
actually i want to read all the mms and store them on server. plz give me suggestions code to read an mms as i am unable to do that yet.
Regardz
Iqra
Once Poster
Once Poster
 
Posts: 1
Joined: Sun Jun 17, 2012 3:16 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Exabot [Bot], Yahoo [Bot] and 15 guests