简体   繁体   中英

Phonegap Filesystem keeps saving to internal storage while there is an SD card

I'm having trouble using the phonegap file API. In my application I'm using the following piece of code to save images from the LocalStorage to the android device.

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) { // If the folder does not exist create it fileSys.root.getDirectory( myFolderApp, { create:true, exclusive: false }, function(directory) { entry.moveTo(directory, newFileName, successMove, resOnError); }, resOnError); }

the variable myFolderApp contains the foldername that needs to be created. The problem is that even tough the android tablet has got an SD card inserted, the applicaton keeps creating the directory (and later saving the data) to the internal storage instead of the external SD card.

localFileSystem.PERSISTENT Should switch to sd card when one is available right? When I log the directory.toURL() it's saying "cdvfile/localhost/persistent/mydirectory"

The native android camera application is saving it's images to the SD card which means the SD card is working properly.

I'm quite lost at this point. After hours of googeling I know the cordova file plugin has recently been updated, and therefore sometimes requires a different approach but I'm still stuck and can't seem to find a solution.

Hope someone can help me. Thanks in advance,

Marco

Try changing in config.xml

<preference name="AndroidPersistentFileLocation" value="Internal" />

to

<preference name="AndroidPersistentFileLocation" value="Compatibility" />

See the following discussion:

https://groups.google.com/forum/#!msg/phonegap/5UeZOBAz_DM/YlaGFJVCpv4J

We need to modify the AndroidManifest.xml file, however we will not do it manually. This is not a good practice as everytime you build your project, your changes will be lost.

Instead we are going to use the cordova-custom-config plugin, which allow you to modify the AndroidManifest.xml file from your config.xml file without problems. To install the plugin execute the following command in your command line :

cordova plugin add cordova-custom-config
# Or phonegap
phonegap plugin add cordova-custom-config

Fortunately, to enable this feature you need add only a property to the AndroidManifest.xml file. Using cordova-custom-config plugin, which allow you to use custom config blocks in your config.xml file of your cordova app, you need to add the following line in the config.xml file inside the tag :

<platform name="android">
   <!-- Modify the android-manifest block and add the new property android:installLocation with value auto !-->
   <preference name="android-manifest/@android:installLocation" value="auto" />
</platform>

Read more about step by step here.

Read more about the plugin here in the official repository here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM