【问题标题】:how to specific sms display on my listview如何在我的列表视图上显示特定的短信
【发布时间】:2014-12-10 12:49:46
【问题描述】:

我希望在应用程序的列表视图中显示特定的短信。现在使用下面的代码,所有的短信都显示在列表视图中。

MainActivity.java 
{
    ListView lViewSMS = (ListView) findViewById(R.id.listViewSMS); 
    if(fetchInbox()!=null)
    { 
        ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, fetchInbox());
        lViewSMS.setAdapter(adapter);
    }
} 
public ArrayList fetchInbox()
{
    ArrayList sms = new ArrayList(); 
    Uri uriSms = Uri.parse("content://sms/inbox");        
    Cursor cursor = getContentResolver().query(uriSms, new String[]{"_id", "address", "date", "body"},null,null,null);
    cursor.moveToFirst();        
    while  (cursor.moveToNext())
    {
        String address = cursor.getString(1);
        String body = cursor.getString(3); 
        System.out.println("======> Mobile number => "+address);
        System.out.println("=====> SMS Text => "+body); 
        sms.add("Address="+address+"\n"+"SMS="+body);
    }
return sms;
}

【问题讨论】:

  • 您想在列表中显示哪些特定的短信?然后只需在 ArrayList 中添加所需的 SMS
  • 你想要sms according to search keyword吗?说清楚。

标签: java android sms


【解决方案1】:

您可以从光标中过滤短信。请参阅this example 他们通过电话号码过滤短信。同样,您可以按短信正文等进行过滤。

【讨论】:

  • 但是手机收件箱中没有显示短信
猜你喜欢
  • 1970-01-01
  • 2019-09-21
  • 1970-01-01
  • 2017-04-29
  • 1970-01-01
  • 2011-06-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多