Created
October 13, 2011 00:02
-
-
Save sbhimavarapuAppc/1282994 to your computer and use it in GitHub Desktop.
Write to an external file Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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