在android中查找并插入所有SMS/MMS消息 [英] Find and interate all SMS/MMS messages in android
问题描述
首先,我发现此答案特别有用.但是,这使我想知道如何找到这样的信息.
First and foremost, I found this answer particularly helpful. However, it made me wonder how one goes about finding such information.
我似乎无法弄清楚如何重复收件箱中的所有邮件.我当前的解决方案使用Uri.parse("content://mms-sms/conversations")
,其中我给出了"_id"和"ct_t".但是,尽管我有30毫秒的消息,但我似乎只在手机中找到了三个对话(其中20个对话在保存对话线程中,而其他对话则分为两个对话).对于这样的语句content://mms-sms/conversations
将是有意义的.但是,其他提供程序似乎只处理SMS或MMS.没有办法以这种方式迭代整个邮件列表,用其他方式替换"content://mms-sms/conversations"
吗?
I can't seem to figure out how to iterate all the messages in my inbox. My current solution uses Uri.parse("content://mms-sms/conversations")
in which I give use "_id" and "ct_t". However, it seems I only find the three conversations in my phone despite having 30 msges (20 of them in the save conversation thread and the others divided between two other conversations). Would make sense for such a statement content://mms-sms/conversations
. However, the other providers seem to deal only with SMS OR MMS. Isn't there a way to just iterate the entire list of messages in this fashion where I replace "content://mms-sms/conversations"
with something else?
public boolean refresh() {
final String[] proj = new String[]{"_id","ct_t"};
cursor = cr.query(Uri.parse("content://mms-sms/conversations"),proj,null,null,null);
if(!(cursor.moveToFirst())) {
empty = true;
cursor.close();
return false;
}
return true;
}
我使用下一个函数迭代消息
I iterate the messages with a next function
public boolean next() {
if(empty) {
cursor.close();
return false;
}
msgCnt = msgCnt + 1;
Msg msg;
String msgData = cursor.getString(cursor.getColumnIndex("ct_t"));
if("application/cnd.wap.multipart.related".equals(msgData)) {
msg = ParseMMS(cursor.getString(cursor.getColumnIndex("_id")));
} else {
msg = ParseSMS(cursor.getString(cursor.getColumnIndex("_id")));
}
if(!(cursor.moveToNext())) {
empty = true;
cursor.close();
return false;
}
return true;
}
推荐答案
是否没有办法以这种方式迭代整个邮件列表,而我将
"content://mms-sms/conversations"
替换为其他内容?
Isn't there a way to just iterate the entire list of messages in this fashion where I replace
"content://mms-sms/conversations"
with something else?
可以使用content://mms-sms/complete-conversations
URL在一次查询中获取所有MMS和SMS消息.出于某些奇怪的原因,在
It is possible to get all MMS and SMS messages in a single query using the content://mms-sms/complete-conversations
URL. For some odd reason, there is no Uri
field for this in the Telephony.MmsSms
class, but it's been available since at least Froyo.
使用此单个查询肯定比分别查询表更有效,并且与Java集合相比,SQLite引擎执行所需的任何排序,分组或筛选肯定会更快.
Using this single query will certainly be more efficient than querying the tables separately, and any sorting, grouping, or filtering that needs to be done will definitely be faster performed by the SQLite engine than by manipulating Java collections.
请注意,此查询必须使用特定的projection
.您不能传递null
或*
通配符.此外,建议在projection
中包含MmsSms.TYPE_DISCRIMINATOR_COLUMN
("transport_type"
)-其值将为"mms"
或"sms"
-以轻松区分消息类型.
Please note that you must use a specific projection
for this query. You cannot pass null
or the *
wildcard. Furthermore, it would be advisable to include MmsSms.TYPE_DISCRIMINATOR_COLUMN
("transport_type"
) in your projection
- which will have a value of either "mms"
or "sms"
- to easily distinguish the message type.
selection
,selectionArgs
和orderBy
参数照常工作,并且可以为任何或所有参数传递null
.
The selection
, selectionArgs
, and orderBy
arguments work as usual, and null
can be passed for any or all of them.
这篇关于在android中查找并插入所有SMS/MMS消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!