Created
August 23, 2013 21:00
-
-
Save ricardoalcocer/6323964 to your computer and use it in GitHub Desktop.
Appcelerator Android share photo with Instagram
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function showgallery(){ | |
Titanium.Media.openPhotoGallery({ | |
success:function(event){ | |
var cropRect = event.cropRect; | |
var image = event.media; | |
Ti.API.debug('Our type was: '+event.mediaType); | |
if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO){ | |
var uri = image.nativePath; | |
var igIntent = Ti.Android.createIntent({ | |
action:Ti.Android.ACTION_SEND, | |
packageName:"com.instagram.android", | |
type:"image/*" | |
}); | |
igIntent.putExtraUri(Titanium.Android.EXTRA_STREAM, uri); | |
setTimeout(function(){ | |
Ti.Android.currentActivity.startActivity(igIntent); | |
}, 400); | |
}else{ | |
// is this necessary? | |
} | |
Titanium.API.info('PHOTO GALLERY SUCCESS cropRect.x ' + cropRect.x + ' cropRect.y ' + cropRect.y + ' cropRect.height ' + cropRect.height + ' cropRect.width ' + cropRect.width); | |
}, | |
cancel:function(){ | |
}, | |
error:function(error){ | |
}, | |
allowEditing:true, | |
mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO] | |
}); | |
} |
This code works for photos and videos =>
if (Ti.Platform.osname == 'android') {
var intent = Ti.Android.createIntent({
action: Ti.Android.ACTION_SEND
});
if (isvideo) {
intent.setType('video/*');
}
else {
intent.setType('image/*');
}
intent.putExtra(Ti.Android.EXTRA_TEXT, args.status);
if (args.image) {
intent.putExtraUri(Ti.Android.EXTRA_STREAM, args.image);
}
var shareActivity = Ti.Android.createIntentChooser(intent, "Share with");
Ti.Android.currentActivity.startActivity(shareActivity);
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice. Thanks! I'm looking for the same thing, but for sharing it on iOS. Got any references? I've tried using a DocumentViewer, but so far no luck.