Results 1 to 4 of 4

Thread: how to save downloaded files to external memory on android

  1. #1
    Sencha User =NR='s Avatar
    Join Date
    Mar 2013
    Location
    Singapore
    Posts
    115
    Answers
    2

    Default Answered: how to save downloaded files to external memory on android

    Hi there,

    I know it's more of phonegap related but hence there is no harm in trying.

    Does anyone here know article/example/guide on how to save the downloaded file (using phonegap's filetransfer.download()) to external storage on android ?

    Most of article that i came accross said that "LocalFileSystem.PERSISTENT,0, .." will by default save your file to external storage (sd card) if the external storage exist otherwise it will write to the device internal storage.

    I've tried to verify this and that is not actually happens as even thought my external storage is mounted and empty, phonegap still write all the files to device internal storage.


    Regards,

  2. the problem lies in android,as "external storage" can be:- part of internal storage partioned/defined as external storage (emulated version)- real physical storage (sd card)and by OS, before kitkat with phonegap it will only returns the first "external storage" it found (most of the time will be emulated).Another pitfall is the phonegap's DirectoryEntry.getDirectory() that will throw an error if the immediate parent folder does not exist and somehow will still throw an error if the exact folder path does exist (tried adding the write permission yet still fail) so we need to have function that will create directory and all its subdirectories.that being said, tried my hands on cordova plugin and call android native methods for all that related to the storage (storage state, getExternalFilesDir(), etc) still its not giving me the exact physical storage ( I want reliable path to my application's folder on the physical external storage).summary: android is a mess, they offer feature yet no reliable way to utilize that.

  3. #2
    Sencha User
    Join Date
    Mar 2012
    Location
    Lawrence, KS
    Posts
    462
    Answers
    65

    Default

    I've found a few guides/tutorials. Some of them are a bit dated, but may still be relevant:

    http://simonmacdonald.blogspot.nl/20...negapping.html
    http://docs.phonegap.com/en/2.6.0/co...ocalFileSystem
    https://groups.google.com/forum/#!to...ap/BOpoa9HBFjE
    http://stackoverflow.com/questions/9...in-the-sd-card
    http://stackoverflow.com/questions/1...using-phonegap

    I'm not sure what version of PhoneGap you're using, so you may need to find alternatives on some of the API guides.

    Thanks!
    Greg

  4. #3
    Sencha User =NR='s Avatar
    Join Date
    Mar 2013
    Location
    Singapore
    Posts
    115
    Answers
    2

    Default

    Quote Originally Posted by greg.barry View Post
    I've found a few guides/tutorials. Some of them are a bit dated, but may still be relevant:http://simonmacdonald.blogspot.nl/20...negapping.htmlhttp://docs.phonegap.com/en/2.6.0/co...ocalFileSystemhttps://groups.google.com/forum/#!to...ap/BOpoa9HBFjEhttp://stackoverflow.com/questions/9...in-the-sd-cardhttp://stackoverflow.com/questions/1...using-phonegapI'm not sure what version of PhoneGap you're using, so you may need to find alternatives on some of the API guides.Thanks!Greg
    Hi Greg,Thanks for the reply, really appreciate the effort of putting all those link into this thread. Yeah I've been to most of those links but couldn't really get it.Basically those article is saying that this statement will write those file to external storage of android's device if the storage is mounted.
    Code:
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);
    But I've tried it and practically is my current logic yet its still using the internal storage.There is also other suggestion of getting some root path of the file system and then modify it so it pointing to the sdcard / external storage.But this solution have one fatal letdown which is the sdcard can be called one of two possibilities (by least i meant I'm just aware of 2 name posibilities) and I don't how to overcome that and doesn't seems reliable enough.Basically just trying to have some of the application files to be stored in the external storage which will also be cleaned when the app is uninstalled. because my application have tons of files and media files which is consuming the storage space.

  5. #4
    Sencha User =NR='s Avatar
    Join Date
    Mar 2013
    Location
    Singapore
    Posts
    115
    Answers
    2

    Default

    the problem lies in android,as "external storage" can be:- part of internal storage partioned/defined as external storage (emulated version)- real physical storage (sd card)and by OS, before kitkat with phonegap it will only returns the first "external storage" it found (most of the time will be emulated).Another pitfall is the phonegap's DirectoryEntry.getDirectory() that will throw an error if the immediate parent folder does not exist and somehow will still throw an error if the exact folder path does exist (tried adding the write permission yet still fail) so we need to have function that will create directory and all its subdirectories.that being said, tried my hands on cordova plugin and call android native methods for all that related to the storage (storage state, getExternalFilesDir(), etc) still its not giving me the exact physical storage ( I want reliable path to my application's folder on the physical external storage).summary: android is a mess, they offer feature yet no reliable way to utilize that.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •