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.
Download the finished code from this link and import it into Appcelerator Studio.
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.
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’.
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
Pass the intent to the function Ti.Android.currentActivity.startActivity(), and surround that with a try catch block.
If an exception is thrown show an alert notifying the user that there are no sharing apps available to use.
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.