Skip to content

Instantly share code, notes, and snippets.

@ricardoalcocer
Created August 23, 2013 21:00
Show Gist options
  • Save ricardoalcocer/6323964 to your computer and use it in GitHub Desktop.
Save ricardoalcocer/6323964 to your computer and use it in GitHub Desktop.
Appcelerator Android share photo with Instagram
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]
});
}
@adamgf
Copy link

adamgf commented Nov 22, 2018

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