在我的 android 应用中显示来自一个特定发件人的所有短信

Displaying all SMS from one specific sender in my android app

我的应用程序当前在收件箱中显示所有带有以下代码的短信:

public void onClick(View v) {

    if (v == btnInbox) {

        // Create Inbox box URI
        Uri inboxURI = Uri.parse("content://sms/inbox");

        // List required columns
        String[] reqCols = new String[]{"_id", "address", "body"};

        // Get Content Resolver object, which will deal with Content
        // Provider
        ContentResolver cr = getContentResolver();

        // Fetch Inbox SMS Message from Built-in Content Provider
        Cursor c = cr.query(inboxURI, reqCols, null, null, null);

        // Attached Cursor with adapter and display in listview
        adapter = new SimpleCursorAdapter(this, R.layout.row, c,
                new String[]{"body", "address"}, new int[]{
                R.id.lblMsg, R.id.lblNumber});
        lvMsg.setAdapter(adapter);

    }
}

并且我只想显示来自一个特定发件人的邮件,我要更改什么以消除来自其他发件人的邮件?

应用选择参数根据地址字段过滤内容。

实际代码变为:

String[] selectionArgs = { "12672631" }; //add the phone number here
Cursor c = cr.query(inboxURI, reqCols, "address=?", selectionArgs, null);