1
votes

I'm trying to use Twilio Api to send SMS to my phone from my Android Kotlin App

I'm putting the initialization of twilio on the onCreate Method https://i.imgur.com/3D75hLn.png

Where sid is my Twilio SID and token is my Twilio TOKEN

and this is the function i'm executing after that to send the message https://i.imgur.com/knuXGt7.png

But i'm getting this error when executing the program https://i.imgur.com/a2rr8on.png

I have INTERNET and SEND_SMS permissions in my manifest.xml

Did anyone already tried Twilio With kotlin 1ndroid ? thanks for your help

I've tried creating a new Android projet and invalidate the cache

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_register)

        Twilio.init(sid, token)

        register_button.setOnClickListener {
            performRegister()
            Log.i("Register", generatePassword())
        }
    }
fun sendPasswordMessage() {
                val message = Message.creator(
            PhoneNumber("+213793079458"),
            PhoneNumber("+14075452670"),
            "Hello from aziz"
        ).create()
        println(message.sid)

    }
1

1 Answers

1
votes

Twilio developer evangelist here.

We strongly recommend that you do not try to use the Twilio API directly from your Android application like this.

Storing and using your credentials within the application makes it vulnerable to attack. A malicious user could decompile your application, extract your credentials and use them to abuse your account.

While this blog post is written in Java rather than Kotlin, it provides a template for how to send SMS messages using Twilio and Android. The summary is that you should interact with the Twilio API from a server where you can keep your credentials safe and that your Android application should make HTTP requests to your server.