0

我正在使用 Kotlin 构建一个 Android 应用程序。我的应用需要接收彩信。我还试图从彩信详细信息中检索发件人的地址/电话号码。但它没有按预期工作。

这是我用来从彩信中检索发件人地址的函数

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

有时,它似乎在起作用。然后我抛出以下错误

Index -1 requested, with a size of 1

您认为我的代码有什么问题,我该如何解决?

4

0 回答 0