Android forced external SD card with cord and file plugin

In the cordova Android developer application (scroll to the bottom for the device, version, list of plug-ins, all this is absolutely relevant at the time of this writing). I want to mainly store the file on an external SD card and use internal storage if the SDCard is not there. I set my save path:

persistentFS= cordova.file.externalDataDirectory||cordova.file.DataDirectory||fileSystem.root.toURL();

Its final value is the file: ///storage/emulated/0/Android/data/com.fubar.app/files/, the same as cordova.file.externalDataDirectory.

I set: <access origin="cdvfile://*" /> ... <preference name="AndroidPersistentFileLocation" value="Compatibility" /> <preference name="AndroidExtraFilesystems" value="files-external,sdcard,files,documents,cache,cache-external,root" /> in config.xml, <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

in AndroidManifest.xml and set various enchantments in index.html Security Metadata. I add that an SD card is inserted, recording is enabled, and I confirm that I can write with it, for example, with a file manager. This contains the Android / data / com.fubar.myapp / files / folder, as it should be.

All for nothing: files are written to - and read from - internal device storage. I read all google in this thread, but nothing brought me closer to the task (some people suggest using a plugin with file systems, but it seems to have been added by a file plugin).

Any clues? TIA, Alf

Edit: Using the adb shell, I see that the external sdcard folder for the application has an absolute path:

 `/storage/extSdCard/Android/data/com.fubar.myapp/files` 

and call resolveLocalFileSystemURL on

file:///storage/extSdCard/Android/data/com.fubar.myapp/files

succeeds happily. I do not think this is the way to go, because this way is device dependent.


Device: Samsung Galaxy Tab 10.5, candy 5.0.1 using cordova 5.3.1, with plugins: cordova-plugin-device 1.0.1 "Device" cordova-plugin-dialogs 1.1.1 "Notification" cordova-plugin-file 3.0. 0 "File" cordova-plugin-file-transfer 1.3.0 "File Transfer" cordova-plugin-media 1.0.1 "Media" cordova-plugin-whitelist 1.1.0 White List

Host assembly is Linux FC21

+5
source share
2 answers

You can call Context.getExternalFilesDirs() . This returns an array of directories into which your application can write data. One of them will be the path sdcard / storage / sdcardname / Android / data / appname / files.

Most manufacturers also set the SECONDARY_STORAGE environment variable to open the root path of the SD Card. You can try calling System.getenv("SECONDARY_STORAGE")

Android does not provide an API that allows you to get the path to the sdcard root path. You can use reflection and get the sdcard root path from StorageManager.java → getVolumePaths () - http://androidxref.com/5.1.1_r6/xref/frameworks/base/core/java/android/os/storage/StorageManager.java# 590

+2
source

Since there seems to be no Cordoba's true answer to this, but here is what I found using the file plugin . I also wanted to save to the SD card, and then the data will be attached to the email, and now Gmail requires the application to be downloaded from the SD. This blog made me go in the right direction https://www.neontribe.co.uk/cordova-file-plugin-examples/ . In the section on writing a file, just replace

 window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function (directoryEntry) { 

with this

 window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function (directoryEntry) { 

And it should work.

0
source

Source: https://habr.com/ru/post/1232277/


All Articles