Endereço

Rua Cônego Jerônio Pimentel, 299 - Umarizal - Belém - Pa

Contato

contato@igorgoldim.com.br
(91) 99353-7150/99282-1866

Atendimento

Seg-Sex: 08:00 às 22.00
Sábado: 08:00 às 14:00

Título

Autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et dolore feugait.

Arquivo de tag

Send SMS with Kotlin for android Studio

val SENT = "SMS_SENT"
val DELIVERED = "SMS_DELIVERED"

var sentPI = PendingIntent.getBroadcast(context, 0, Intent("SMS_SENT"), 0)
var deliveredPI = PendingIntent.getBroadcast(context, 0, Intent("SMS_DELIVERED"), 0)

context.registerReceiver(object : BroadcastReceiver() {
     override fun onReceive(p0: Context?, p1: Intent?) {
      when(resultCode){
           Activity.RESULT_OK -> Toast.makeText(context, "SMS Enviada", Toast.LENGTH_LONG).show()
           SmsManager.RESULT_ERROR_GENERIC_FAILURE -> Toast.makeText(context, "Erro ao enviar SMS falha generica", Toast.LENGTH_LONG).show()
            SmsManager.RESULT_ERROR_NO_SERVICE -> Toast.makeText(context, "Erro ao enviar SMS sem servico", Toast.LENGTH_LONG).show()
            SmsManager.RESULT_ERROR_NULL_PDU -> Toast.makeText(context, "Erro ao enviar SMS PDU Nulo", Toast.LENGTH_LONG).show()
             SmsManager.RESULT_ERROR_RADIO_OFF -> Toast.makeText(context, "Erro ao enviar SMS Sem sinal", Toast.LENGTH_LONG).show()
                    }
                }
            }, IntentFilter(SENT))


context.registerReceiver(object : BroadcastReceiver() {
     override fun onReceive(p0: Context?, p1: Intent?) {
      when(resultCode){
           Activity.RESULT_OK -> Toast.makeText(context, "SMS Enviada", Toast.LENGTH_LONG).show()
           Activity.RESULT_CANCELED -> Toast.makeText(context, "SMS não Enviada", Toast.LENGTH_LONG).show()
           else -> Toast.makeText(context, "Erro ao enviar SMS", Toast.LENGTH_LONG).show()
                    }
                } }, IntentFilter(DELIVERED))


val smsManager = SmsManager.getDefault()
            smsManager.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI)