Sharing photo on Instagram on Android using Titanium

Posted By : Akshay Luthra | 17-Nov-2015

Photo Sharing Instagram using Titanium

This blog is written to provide a ready code in Titanium for sharing photo on Instagram app.


You need to have the Instagram app installed on your Android device to share a photo in it.


The code written in this blog will download the image from a photoURL (say, sent from your Server), will save the image on your device and then will share the image on native Instagram app (only if the Instagram app is installed on your device).


if (! {
	alert("No Internet Connection");
} else {

	var dir = (!Ti.Android || !Ti.Filesystem.isExternalStoragePresent()) ? Ti.Filesystem.applicationDataDirectory : Ti.Filesystem.externalStorageDirectory;
	var localStorage = Ti.Filesystem.getFile(dir, "IMAGES_FOLDER");
	(!localStorage.exists()) && localStorage.createDirectory();
	var imageFilePath = Ti.Filesystem.getFile(localStorage.resolve(), 'image.png');

	var xhr = Ti.Network.createHTTPClient({
		onload : function(e) {

			if (this.status == 200) {

				if (Ti.Android) {

					var igIntent = Ti.Android.createIntent({
						action : Ti.Android.ACTION_SEND,
						packageName : "",
						type : "image/*"
					igIntent.putExtraUri(Titanium.Android.EXTRA_STREAM, imageFilePath.nativePath);
					setTimeout(function() {
						try {
						} catch (e) {
							alert("Instagram app is not installed in your device!");
					}, 400);

			} else {
				alert("Error occurred while sharing on Instagram");
		onerror : function(e) {
			alert("Unable to proceed due to slow Internet Connection");

	xhr.setTimeout(10 * 1000);'GET', photoURL);





About Author

Author Image
Akshay Luthra

Akshay Luthra has excellent experience in developing Cross Platform Mobile Apps using JavaScript and Titanium Framework. He loves listening to music and travelling new places.

Request for Proposal

Name is required

Comment is required

Sending message..