Photo gallery integration
The last segment of this chapter will allow our users to save any picture they like from the application into their device's photo gallery. Both iOS and Android provide their own brand of photo gallery so that each can be addressed specifically.
The very first thing we will do is to add an event handler when the user clicks on the Save button:
btnSave.addEventListener('click', function() {
Android photo gallery integration
In this handler, we will isolate the code specific to Android in a conditional block:
if (Ti.Android) {
We first need to determine a directory where our photo will be saved on the device. In our case, we will be using the externalStorageDirectory
property that is the path to the device's storage (such as an SD card).
var tempDir = Ti.Filesystem.externalStorageDirectory;
Tip
It is recommended to check if the location is available using the isExternalStoragePresent
function before accessing it. This will prevent errors in cases where external storage...