How to get the phone number from MMS message URI string in Android

255 Views Asked by At

I am building an Android application using Kotlin. In my app, I need to retrieve the sender address/ phone number of the MMS message from the URI string. I have a URI string in this format, content://mms/inbox/60.

I tried using Id like this

private fun getSenderAddress(messageId: String): String {
        val selection = "_id = $messageId"
        val uri = Uri.parse("content://mms")
        val cursor: Cursor = context.contentResolver.query(uri, arrayOf("*"), selection, null, null) as Cursor
        val phone:String = cursor.getString(cursor.getColumnIndex("address"))
        return phone
    }

It is not working. It is saying that the address column is not valid. How can I get the sender's phone number from the MMS message URI string, content://mms/inbox/60?

0

There are 0 best solutions below