Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.6K
Vistas
SMSmanager.getDefault() - DEPRECATION - what to replace?

Recently I started studying programming for the android system in the kotlin programming language. When writing a simple application for sending SMS from the application itself, I ran into the problem that SmsManager.getDefault() is now DEPRECATION and, accordingly, it is not possible to send SMS as indicated in the video lessons. Question - how is it now possible to send SMS from the app itself? I read the official documentation, but could not understand the solution method.

package com.example.mysendsms

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.telephony.SmsManager
import com.example.mysendsms.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {
    lateinit var binding: ActivityMainBinding
    val sms = SmsManager.getDefault()

    override fun onCreate(savedInstanceState: Bundle?) {
        binding = ActivityMainBinding.inflate(layoutInflater)
        super.onCreate(savedInstanceState)
        setContentView(binding.root)

        binding.send.setOnClickListener {
            val textMsg = binding.message.toString().trim()
            val numberMsg = binding.number.toString().trim()
            sendSMS(textMsg,numberMsg)
        }
    }

    private fun sendSMS(text: String, number: String) {
            sms.sendTextMessage(number,null,text,null,null)
        }
    }
}
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

By official documentation you can get it like this

val smsManager = context.getSystemService(SmsManager::class.java)
over 4 years ago · Santiago Trujillo Denunciar

0

SmsManager getDefault() method is only deprecated starting from API 31, so you should still use getDefault() APIs levels below the 31.

val smsManager: SmsManager = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            context.getSystemService(SmsManager::class.java)
        } else {
            SmsManager.getDefault()
        }
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda