Skip to content

Instantly share code, notes, and snippets.

@himalay
Forked from FokkeZB/share.js
Last active August 29, 2015 14:17
Show Gist options
  • Save himalay/0c93a49d329e634ec7c1 to your computer and use it in GitHub Desktop.
Save himalay/0c93a49d329e634ec7c1 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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment