How to allow users to take a screenshot with Titanium Mobile SDK

take a screenshot with Titanium Mobile SDK
take a screenshot with Titanium Mobile SDK

Dear Geek,

I want to allow users to take a screenshot of my app when submitting a troubleshooting ticket. My app is built using Titanium Mobile SDK and runs on iOS and Android. Can you show me how to do this?

—   SCREENSHOTS WANTED

Dear Screenshots,

Including a screenshot with user-reported incidents can be a great way to add context for development teams! With Titanium Mobile SDK, it is super easy to take a screenshot and get back an image that you can then upload or email as an attachment.

Titanium code to capture screenshot and save/display


// Take screenshot
Ti.Media.takeScreenshot( e => {

    // the "e.media" property contains the screenshot image

    // You can also display the image on the screen
    $.imageView.image = e.media;

    // Or save the image to photo gallery
    Ti.Media.saveToPhotoGallery(e.media);
});

 

You can find more information about capturing screenshots with Titanium Native mobile apps on the Axway Titanium API Documentation page here.

Ask-a-Geek questions are answered by Brenton House, an API and Mobile geek who has been doing dev work for 25+ years.

Discover more Ask-a-Geek questions and answers here!

2 COMMENTS

  1. I get an error “Failed to create external storage directory.” The docs say: On Android this method only supports saving images to the device gallery prior to Titanium SDK 6.1.0. Does the saveToPhotoGallery() still work on Android? Or was there a replacement method created post SDK 6.1.0?

    • Hi Ben! Prior to Titanium SDK 6.1.0, you could only save images to gallery. With all the recent SDK releases after this, you can save BOTH photos and videos to the device gallery. Hope this help!!

Comments are closed.