我确实获得了关于如何检索从以下链接( How to Read MMS Data in Android? )发送的彩信的文本和图像的信息。
但我不知道如何检索发送的mms的日期。
我知道我必须查看内容://mms,而不是内容://mms/part。
这是检索mms文本的方法:
private String getMmsText(String id) {
Uri partURI = Uri.parse("content://mms/part/" + id);
InputStream is = null;
StringBuilder sb = new StringBuilder();
try {
is = getContentResolver().openInputStream(partURI);
if (is != null) {
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
BufferedReader reader = new BufferedReader(isr);
String temp = reader.readLine();
while (temp != null) {
sb.append(temp);
temp = reader.readLine();
}
}
} catch (IOException e) {
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
}
return sb.toString();
}然后,在onCreate方法中,我使用以下代码获取信息:
Cursor cursor = getContentResolver().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"));
if (data != null) {
// implementation of this method above
body = getMmsText(partId);
} else {
body = cursor.getString(cursor.getColumnIndex("text"));
}
}
} while (cursor.moveToNext());
}
try {
main.setText(body);
img.setImageBitmap(bitmap);
} catch (Exception e) {
e.printStackTrace();
}我只想知道在哪里可以进行更改以获得日期值。
一些信息会很有帮助。
发布于 2014-01-30 15:35:26
我对MMS并不太熟悉,但我想这样的事情至少会让你开始
Cursor cursor = activity.getContentResolver().query(Uri.parse("content://mms"),null,null,null,date DESC);
count = cursor.getCount();
if (count > 0)
{
cursor.moveToFirst();
long timestamp = cursor.getLong(2);
Date date = new Date(timestamp);
String subject = cursor.getString(3);
}当然,这是完全未经测试的,但应该会给你指明正确的方向。希望这能有所帮助!
编辑在做了一些阅读之后,在检索数据时,曾经(可能仍然)有一个带有MMS消息时间戳的"bug“。如果你最终得到了一个愚蠢的值(比如时代),那么你必须在使用它之前使用* 1000。只是旁白:) I.
long timestamp = (cursor.getLong(2) * 1000);https://stackoverflow.com/questions/21460486
复制相似问题