Skip to content

Instantly share code, notes, and snippets.

@yagitoshiro
Created September 28, 2011 09:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yagitoshiro/1247519 to your computer and use it in GitHub Desktop.
Save yagitoshiro/1247519 to your computer and use it in GitHub Desktop.
Titanium Mobile (Android) sample -- save file to sdcard and register to photo gallery.
save_button.addEventListener('click', ()->
if Ti.Filesystem.isExternalStoragePresent
save_image = Ti.Filesystem.getFile(path).read()
new_path = Titanium.Filesystem.externalStorageDirectory + Date.now().toString() + ".png"
f = Ti.Filesystem.getFile(new_path)
result = f.write(save_image)
unless result
return null
callback_fn = (e)->
Ti.API.info e
if e.uri
message = L('saved')
else
message = L('error')
alert message
return
Ti.Media.Android.scanMediaFiles([new_path], null, callback_fn)
return
)
@MukundSamant
Copy link

Hi Yagito
Is it possible to save the image in other directory..so that we are not dependent on memory card being present?
From what I understand in the above code we are only saving the image if memory card is present..

@MukundSamant
Copy link

Also I tried using the ApplicationDataDirectory but when I am viewing the image in the gallery it is a blank gray box..Is it because access to ApplicationDataDirectory is restricted to other applications?

@Nexiies
Copy link

Nexiies commented Aug 1, 2014

Did you ever find the solution for this problem ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment