我可以使用查询“content:// mms / part”从设备读取mms图像并将这些mmsimages发送到服务器,但我的要求是在我的应用程序中我将从设备读取所有mms图像并备份到服务器从应用程序打开的第二次起,我需要将最新的mms备份到服务器,为了满足这个要求,我需要在我给出的特定日期之后从设备读取mms。有可能吗?
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;
}
答案 0 :(得分:0)
这是我在评论中讨论的代码(来自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"));
然后,您可以将日期与给定日期进行比较,以确定是否要上传与当前_id相对应的数据。