Time for action – sharing an update using intents
Perform the following steps to share an update using intents:
Add a function that shares an item of text (this text could be shared as a message to Tweet or a post to Facebook) . The function creates an Android intent, sets the type of data to be included with the intent as
text/plain
, and adds the message before launching the intent.function shareUpdate(_args) { var shareThis = Ti.Android.createIntent({ action: Ti.Android.ACTION_SEND, type: "text/plain" }); shareThis.putExtra(Ti.Android.EXTRA_TEXT, _args.comment); shareThis.addCategory(Ti.Android.CATEGORY_DEFAULT); Ti.Android.currentActivity.startActivity(shareThis); }
Link this together by creating a button that when pressed calls the
shareUpdate
function:var shareThisButton = Ti.UI.createButton({title: 'Share'}); shareThisButton.addEventListener('click', function(e) { shareUpdate(); }); layout.add(shareThisButton);
Run the app!
What just happened?
You added...