从收件箱中搜索邮件不成功

时间:2012-12-14 05:34:49

标签: android sms inbox

我希望根据特定的数字从收件箱中获取有关邮件的信息。我使用以下代码来实现目标但是它没有以预期的方式运行:

public void SendTheSmsToTheFolder(String NameOfContact,String Number,String FolderAddress,long TimeLimit)
    {
        m_NameOfContact = NameOfContact;
        String SMS_URI_INBOX = "content://sms/inbox"; 
        Uri l_uri = Uri.parse(SMS_URI_INBOX); 

        Cursor l_SendTheSmsToTheFolderCursor = getContentResolver().query(l_uri, null, "address=?",new         String[]{Number.trim()},null);
        if (l_SendTheSmsToTheFolderCursor.moveToFirst())
        {  
            int l_index_Address = l_SendTheSmsToTheFolderCursor.getColumnIndex("address");  
            int l_index_Person = l_SendTheSmsToTheFolderCursor.getColumnIndex("person");  
            int l_index_Body = l_SendTheSmsToTheFolderCursor.getColumnIndex("body");  
            int l_index_Date = l_SendTheSmsToTheFolderCursor.getColumnIndex("date");  
            do 
            {  
                String l_strAddress = l_SendTheSmsToTheFolderCursor.getString(l_index_Address);  
                String l_strbody = l_SendTheSmsToTheFolderCursor.getString(l_index_Body);  
                long l_longDate = l_SendTheSmsToTheFolderCursor.getLong(l_index_Date);  

                Log.v("Message: ","Body of the message is "+l_strbody);
            } while (l_SendTheSmsToTheFolderCursor.moveToNext());  
        }
}       

我很确定包含该特定电话号码的消息存在于框中,我已经交叉检查了这一事实。但是在这里,我的光标数始终显示为0.我不知道是什么问题。我已经搜索了很多,但我无法弄清楚。请帮助我。谢谢。

1 个答案:

答案 0 :(得分:0)

如果您要搜索特定号码的邮件,可以尝试使用此代码。

 Uri uri = Uri.parse("content://sms/inbox");
    ContentResolver contentResolver = context.getContentResolver();
    String where = "address="+ phNum; //here you can use that particular number
    Cursor cursor = contentResolver.query(uri, new String[] { "_id", "thread_id"}, where, null,null);

它对我有用。如果它解决了您的问题,请告诉我。