0 Replies Latest reply on Jul 21, 2015 5:16 AM by sandhiyad90081458

    How to Write to media card (secondary storage) from an app?


      How to Write to media card (secondary storage) from an app?



      Need to make the installation location as external(secondary storage), i have added the write permission in android manifest and installation location as "preferExternal". For file operation, tried with both "file.documentsDirectory" and "file.usersDirectory". But both results the app data storage in external SD card (primary external storage) and not in the removable SD card. I have tried with android versions like  jellybean, kitkat and lollipop.



      Android version 4.4 (codename KitKat) does not allow applications you install to write to user-installed MicroSD cards.

      Here is the official technical document describing this behavior of android : http://source.android.com/devices/tech/storage/

      Quoted from there:

      The WRITE_EXTERNAL_STORAGE permission must only grant write access to the primary external storage on a device. Apps must not be allowed to write to secondary external storage devices, except in their package-specific directories as allowed by synthesized permissions. Restricting writes in this way ensures the system can clean up files when applications are uninstalled.



      Now Android 5.0 Lollipop Brings Full SD Card Access for Third-Party Apps. Is it so? then how can i make application to store on removalbe SD card.



      Sample code :

      protected function viewnavigatorapplication1_creationCompleteHandler(event:FlexEvent):void


        var myFile:File = File.documentsDirectory.resolvePath("StorageTest/test.txt"); 


        var fs:FileStream = new FileStream(); 


        fs.writeUTFBytes("blah blah"); 



        var file:File = File.documentsDirectory.resolvePath("StorageTest"); 


        try { 


        } catch (e:Error) { 

        debugText += e.message;