Sharing photo on Instagram on Android using Titanium
Posted By : Akshay Luthra | 17-Nov-2015
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 (!Ti.Network.online) { alert("No Internet Connection"); return; } 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) { imageFilePath.write(this.responseData); if (Ti.Android) { var igIntent = Ti.Android.createIntent({ action : Ti.Android.ACTION_SEND, packageName : "com.instagram.android", type : "image/*" }); igIntent.putExtraUri(Titanium.Android.EXTRA_STREAM, imageFilePath.nativePath); setTimeout(function() { try { Ti.Android.currentActivity.startActivity(igIntent); } 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); xhr.open('GET', photoURL); xhr.send(); }
THANKS
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
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.