From the course: Android Development: Understanding Intents

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Compose an SMS message

Compose an SMS message - Android Tutorial

From the course: Android Development: Understanding Intents

Start my 1-month free trial

Compose an SMS message

- [Instructor] For the last example in this chapter, let's see how to create an intent that will compose an SMS message and get it ready to be sent by the user's texting app. So here in the MediaActivity.java file, I've scrolled down to the btnClick handler for the SendText button. And I've already declared a string variable that's going to hold our sample text message. So I'm going to create an intent in the usual way and in this case we're going to use the ACTION_SENDTO intent and that's one of the standard intents. So I'm going to write intent and look at that, it's the first option right there. So, in this case I want to make sure that only applications that can handle SMS messages respond to this intent. To do that I'm going to use the setData function of the intent object to specify that this intent contains SMS data. And just like in the example where we opened a web page I'm going to create a URI using the SMS protocol. So what I'm going to do is write i.setData and inside…

Contents