private fun readSms() { val contentResolver = applicationContext.contentResolver val cursor = contentResolver.query( Telephony.Sms.CONTENT_URI, null, null, null, null ) if (cursor != null && cursor.moveToFirst()) { do { val address = cursor.getString(cursor.getColumnIndexOrThrow(Telephony.Sms.ADDRESS)) val body = cursor.getString(cursor.getColumnIndexOrThrow(Telephony.Sms.BODY)) smsList.add("Sender: $address\nMessage: $body") } while (cursor.moveToNext()) } cursor?.close() } ======================= if (ActivityCompat.checkSelfPermission( applicationContext, Manifest.permission.READ_SMS ) == PackageManager.PERMISSION_GRANTED ) { readSms() } else { requestPermissions(arrayOf(Manifest.permission.READ_SMS), 1) }