Skip to content

Instantly share code, notes, and snippets.

@FokkeZB
Last active April 1, 2016 14:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save FokkeZB/4636528 to your computer and use it in GitHub Desktop.
Save FokkeZB/4636528 to your computer and use it in GitHub Desktop.
A simple example of using Android intents to share texts, URLs and files like you could do using 0x82's ShareKit module (https://marketplace.appcelerator.com/apps/741) or any other similar module (TiSocial: https://github.com/viezel/TiSocial.Framework) for iOS.
function share(options) {
if (OS_ANDROID) {
var intent = Ti.Android.createIntent({
action: Ti.Android.ACTION_SEND
});
intent.putExtra(Ti.Android.EXTRA_SUBJECT, options.title);
if (options.link) {
intent.putExtra(Ti.Android.EXTRA_TEXT, options.link);
}
if (options.text) {
intent.putExtra(Ti.Android.EXTRA_TEXT, options.text);
}
if (options.image) {
intent.putExtraUri(Ti.Android.EXTRA_STREAM, options.image.nativePath);
}
if (options.file) {
intent.putExtraUri(Ti.Android.EXTRA_STREAM, options.file.nativePath);
}
var share = Ti.Android.createIntentChooser(intent, 'Delen');
Ti.Android.currentActivity.startActivity(share);
} else if (OS_IOS) {
if (options.image) {
options.image = options.image.read();
}
if (options.file) {
options.file = options.file.read();
}
require('com.0x82.sharekit').share(options);
}
}
exports.share = share;
@FokkeZB
Copy link
Author

FokkeZB commented Jan 25, 2013

Please note that for both the iOS and Android implementation you'd have to play with passing the right options. For example: passing both an image and a link will trigger different services (behavior) then just passing a link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment