Can't get picture from applicationDataDirectory to show.
I have some pictures in the Titanium.Filesystem.applicationDataDirectory. The alert picks them up:
("110-10-10", "110-10-10.png", "110-10-8.png", "110-10-9.png").
But I'm unable to set one of them as backgroundImage.
This is my first real project in Titanium.
Any help would be appreciated.
var win = Titanium.UI.currentWindow;
var date = new Date();
var day = date.getDate();
var month = date.getMonth();
var year = date.getYear();
var dpct = year+'-'+month+'-'+day+'.png';
var location = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory);
var dir = location.getDirectoryListing();
var images = [];
for (var i in dir) {
images.push(dir[i]);
}
alert(images);
win.backgroundImage = images[1];
1 Answer
-
Accepted Answer
I think images[x] will return something like '110-10-8.png', which is not enough path information - you'd need to do something like
win.backgroundImage = Ti.Filesystem.applicationDataDirectory+images[x]
to get the fully qualified path to the image. Or, you could set backgroundImage to an actual File blob object returned from Ti.Filesystem.getFile.