Search sms Inbox

后端 未结 2 1332
野性不改
野性不改 2021-01-03 15:44

How can I search the sms inbox and show latest message from a special number. For example search for \"999999999\" and show last message received from this number. Is any wa

2条回答
  •  离开以前
    2021-01-03 15:59

    If you only want the last message sent by a specific number use this:

    final Uri SMS_INBOX = Uri.parse("content://sms/inbox");
    Cursor cursor = getContentResolver().query(SMS_INBOX, null, "address = ?", 
            new String[] {"9999999999"}, "date desc limit 1");
    if(cursor.moveToFirst()) {
        // Do something 
        Log.v("Example", cursor.getString(cursor.getColumnIndex("body")));
    }
    cursor.close();
    

    The second answer to How many database columns associated with a SMS in android? is a great reference for different columns in an SMS.

提交回复
热议问题