Skip to end of metadata
Go to start of metadata

Mission: In this lab you will learn Android specific techniques for sharing information from your app.


Specification: You will share data with other apps using intents. Then you will implement the Android-specific method to hide the soft keyboard.

  1. Download the finished code from this link and import it into Appcelerator Studio.

  2. Inside the index controller, there is a listener for when the send button is clicked. First we want to use Ti.UI.Android.hideSoftKeyboard() to hide the keyboard.

  3. Now we created a variable called intent and used Ti.Android.createIntent() to create the intent we will use. The intent will have an action property that will be Ti.Android.ACTION_SEND, and a type that is ‘text/plain’.

  4. Next we put the information the user typed in the boxes into our intent. This is done by calling putExtra() on the intent. The extras will be EXTRA_SUBJECT and EXTRA_TEXT. Put the relevant input from the user into these extras

  5. Pass the intent to the function Ti.Android.currentActivity.startActivity(), and surround that with a try catch block.

  6. If an exception is thrown show an alert notifying the user that there are no sharing apps available to use.

  7. Compile and run your app on an Android emulator or device. It is preferable to test this on a real device because the emulator might not have compatible sharing apps installed. Now after pressing the send button, you will be able to send a message using your preferred app.

  • No labels