Reading last sms from a particular sender

前端 未结 1 724
甜味超标
甜味超标 2021-01-17 06:44

Im building a app that is reading last sms from spec number (vb# 8888). Code is working great. I only have one prob. When i get a new sms from other number (vb# 7777)my code

1条回答
  •  北海茫月
    2021-01-17 06:57

    Your code is just reading the most recent message in the inbox, whomever it's from. If you want the most recent message from that particular number, you can adjust your query to match the number, and limit the results to one record.

    Uri mSmsinboxQueryUri = Uri.parse("content://sms/inbox");
    String[] projection = {"address", "body"};
    String phoneNumber = "+597*******";
    
    Cursor cursor1 = getContentResolver().query(mSmsinboxQueryUri,
                                                projection,
                                                "address = ?",
                                                new String[] {phoneNumber},
                                                "date DESC LIMIT 1");
    
    if (cursor1 != null && cursor1.moveToFirst()) {
        body = cursor1.getString(cursor1.getColumnIndex("body"));
        Koers = (TextView) findViewById(R.id.Koersdiedag);
        Koers.setText(body);
    }
    

    0 讨论(0)
提交回复
热议问题