I am trying to read a user's SMS messages and get the sender's phone number of those messages. When I try getting the sender's phone number of the message through the "address"
column, it returns the phone number of the text's conversation (for example, if I send a message to a user with phone number X, the address
column returns X instead of my phone number), not the phone number of the person that sent the message. Below is my Kotlin code:
var cursor = contentResolver.query(
Uri.parse("content://sms/"),
null,
null,
null,
null
)
// Retrieve the IDs of the sender's name
var senderID = cursor!!.getColumnIndex("address")
// Iterate through every message
while (cursor!!.moveToNext()) {
var messageSender = cursor.getString(senderID) // Get the sender of the message
System.out.println("---------------------------------------------------------")
System.out.println(messageSender) // Returns phone number of the conversation, not the sender
}
For example: user with phone number 123456789 sends a message to you. I want to retrieve phone number 123456789.