如何根据内部数据库中保存的数字获取短信

时间:2017-05-02 10:26:12

标签: java android for-loop

我有一个小查询。如何获取仅存储在内部数据库中的特定移动号码的SMS。这是我尝试的下面的代码,但我只能得到一个数字

for (Contact_pojo contpojo: smslist) {
        while (cur.moveToNext()) {
            SMS_Adapter sms_adapter = new SMS_Adapter();
            if (cur.getString(cur.getColumnIndexOrThrow("address")).equals("+91"+contpojo.getContactnumber())){
                sms_adapter.setSmsname(cur.getString(cur.getColumnIndexOrThrow("address")));
                sms_adapter.setSmsaddress(cur.getString(cur.getColumnIndexOrThrow("body")));
                smsadapter.add(sms_adapter);
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

试试这个

SMS_Adapter sms_adapter = new SMS_Adapter();
for (Contact_pojo contpojo: smslist) {
        while (cur.moveToNext()) {
            if (cur.getString(cur.getColumnIndexOrThrow("address")).contains("+91"+contpojo.getContactnumber())){
                sms_adapter.setSmsname(cur.getString(cur.getColumnIndexOrThrow("address")));
                sms_adapter.setSmsaddress(cur.getString(cur.getColumnIndexOrThrow("body")));
                smsadapter.add(sms_adapter);
            }
        }
    }

您可以使用contains方法代替equals