by 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
}
}
}