我想得到(TO)保存为草稿的短信地址。我已经尝试了对canonical_addresses表的查询,它在日志中给我发送消息“无法找到canonical_addresses的提供者信息”。 然后我尝试了对sms / draft表的查询,它将null作为地址。 我的代码有什么问题?我该如何获得有关草案短信的信息?我搜索过但没有得到任何解决方案.Plz建议我解决一些问题。
答案 0 :(得分:0)
方法是获取与草稿消息对应的thread_id
。使用thread_id
public String getPhoneNumbersFromThreadID(Context ctx, String threadId)
{
//System.out.println(threadId);
String phoneList = "";
ArrayList<String> phoneCheckList = new ArrayList<String>();
if(thread2Phone.containsKey(threadId))
{
return thread2Phone.get(threadId);
}
if(threadId == null || threadId.equals(""))
{
return "No Name";
}
if(threadId.trim().length() == 0) return "No Name";
Cursor c = ctx.getContentResolver().query(SMSMainListActivity.Sms_CONTENT_URI,
null,
"thread_id = '" + threadId + "'", null, "date ASC");
if (c != null) {
try {
if (c.moveToFirst()) {
while (c.isAfterLast() == false) {
String num = c.getString(c
.getColumnIndex("address"));
num = num.replaceAll(";", ",");
String[] thisNum = num.split(",");
for (int i=0; i<thisNum.length; i++)
{
phoneCheckList.add(formatNumber(thisNum[i])) ;
}
c.moveToNext();
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally
{
c.close();
}
}
try {
phoneCheckList = removeDuplicates(phoneCheckList);
Iterator it = phoneCheckList.iterator();
int i = 0;
while (it.hasNext()) {
String name = ""+it.next();
//System.out.println("Iterated "+name);
if(i==0)
phoneList = ""+name;
else
phoneList += ";"+name;
i++;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
phoneCheckList.clear();
thread2Phone.put(threadId, phoneList);
return phoneList;
}