este codigo esta com problema de logica pode me ajudar a resolver : package com.example.comrecupera

import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.database.Cursor
import android.location.LocationManager
import android.net.Uri
import android.os.Bundle
import android.telephony.SmsManager
import android.telephony.SubscriptionManager
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.getSystemService

class MainActivity : AppCompatActivity() {
    var CONTENT_URI = Uri.parse("content://com.seguro.Fones/celular")


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        onClickShowDetails(null)
    }

    fun onClickShowDetails(view: View?) {
        val cursor = contentResolver.query(
            Uri.parse("content://com.seguro.Fones/celular"),
            null,
            null,
            null,
            null
        )

        var telefone1: NAME_1? = null
        var telefone2: NAME_1? = null
        var telefone3: NAME_1? = null

        if (cursor!!.moveToFirst()) {
            val phoneColumnIndex = cursor.getColumnIndex("fone")
            if (phoneColumnIndex == -1) {
                return
            }
            var count = 0
            while (!cursor.isAfterLast && count < 3) {
                val phone = cursor.getString(phoneColumnIndex)
                when (count) {
                    0 -> {
                        telefone1 = phone
                        Log.d("MainActivity", "telefone_1: $telefone1")
                    }

                    1 -> {
                        telefone2 = phone
                        Log.d("MainActivity", "telefone_2: $telefone2")
                    }

                    2 -> {
                        telefone3 = phone
                        Log.d("MainActivity", "telefone_3: $telefone3")
                    }
                }
                cursor.moveToNext()
                count++
            }
        }
    }
    enviarMensagem()

}

private fun enviarMensagem() {
    val requestLocationPermission = 1
    val locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager
    val smsManager =
        SmsManager.getSmsManagerForSubscriptionId(SubscriptionManager.getDefaultSubscriptionId())

    // Verifica se o app tem permissã