Skip to content

Instantly share code, notes, and snippets.

@sbhimavarapuAppc
Created October 13, 2011 00:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbhimavarapuAppc/1282994 to your computer and use it in GitHub Desktop.
Save sbhimavarapuAppc/1282994 to your computer and use it in GitHub Desktop.
Write to an external file Android
var win = Ti.UI.createWindow({backgroundColor: 'white'});
var dir = Titanium.Filesystem.getFile(Titanium.Filesystem.externalStorageDirectory);
Ti.API.info(dir.nativePath);
var testfile = Ti.Filesystem.getFile(dir.nativePath, 'text.txt');
testfile.write('Hello');
Ti.API.info('external directoryListing = ' + dir.getParent().getDirectoryListing());
Ti.API.info('text.txt exists? ' + testfile.exists());
Ti.API.info('text.txt size: ' + testfile.size + ' bytes');
Ti.API.info("------------");
Ti.API.info("Test file contents:\n" + (testfile.read()).text);
alert(testfile.nativePath);
win.open();
var win = Ti.UI.createWindow({backgroundColor: 'white'});
var dir = Titanium.Filesystem.getFile(Titanium.Filesystem.externalStorageDirectory);
var file ;
Titanium.Media.showCamera({
success:function(event)
{
var cropRect = event.cropRect;
var image = event.media;
Titanium.Media.saveToPhotoGallery(image);
if(Titanium.Filesystem.isExternalStoragePresent) {
// create a new file
file = Titanium.Filesystem.getFile(dir.nativePath, 'image.png');
file.write(image);
alert(file.read() + ' ' + file.size + ' ' + file.nativePath);
Titanium.UI.createAlertDialog({title:'Photo Gallery',message:'Check your photo gallery'}).show();
imageView.image = file.read();
win.add(imageView);
}
}
});
var imageView = Ti.UI.createImageView();
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment