We're developing an android application with cordova were files will be synchronized.
Cordova is up to date, but the problem is that our files are saved in the main storage directory.
The file url looks like:
file:///storage/emulated/0/{our_directory}//
After a cordova update we were forced to set
<preference name="AndroidPersistentFileLocation" value="Compatibility" /> in the config.xml, for still finding our files.
Now we really would like to have our files in the internal data directory.
So if course we just could remove the "Compatibility" setting in the config.xml but then all files would be invisible.
If we change to internal data directory we are having two problems:
In a transition period we need to have access on both directories (Compatibility: file:///storage/emulated/0/{our_directory}// and the new correct internal data directory: file:///data/user/0/{our_app_id}/files/files/{our_directory}//).
If we change to interal window.requestFileSystem(LocalFileSystem.PERSISTENT,0,fn) delivers the root directory of the internal app data directory. So how can I read or write to files which are not in this directory? I found out, that cordova.file.externalRootDirectorydelivers the old path. Any ideas on how to access to both directories?
The other thing is, that we may would like to move all the files from the old directory into the new correct internal app data directory. Any ideas on how to do this?
Thanks ahead!
If you already know the URL you want to store and retrieve files from you can use:
window.resolveLocalFileSystemURL(URL, callback);
The callback will be passed the directory entry.
To move files you can use the fileEntry method moveTo.
entry.moveTo(parentEntry, "newFile.txt", success, fail);
I know this documentation is for Cordova 3.3.0 but I believe it is still relevant.
https://cordova.apache.org/docs/en/3.3.0/cordova/file/fileentry/fileentry.html
Related
I am making an app which use the following java line:
Net dnnNet = Dnn.readNetFromONNX("path\to\file");
As you can see, readNetFromONNX requires path to onnx file.
So I put my onnx file under assest folder, so I can use it at run time.
The problem is I you can only read assets foler with AssestManager and inputstream... the readNetFromONNX needs path...
How do I overcome this probelm? Is there a way to get the path of the file at run time? Maybe other folder?
Thanks from advance
I want to know the correct steps to keep local saved data after app update.
I confirmed the following old question, but I can't solve the issue.
Save app data in kivy on Android
I tried the following.
1-1:I made android APK with buildozer(command:buildozer android debug). 1-2:And execute 'store.put' method using 'kivy.storage'. then 'hello.json' file was created in the './' directory.
https://kivy.org/doc/stable/api-kivy.storage.html
1-1:'./' directory in APK ver.1
main.pyo
1-2:'./' directory in APK ver.1
main.pyo, hello.json(created)
2-1:I made android APK ver.2(same app name as 1.APK). 2-2:After installing in update mode, execute only 'store.get' method using 'kivy.storage'. then method failed because 'hello.json' file was automatically deleted with app update.
2-1:'./' directory in APK ver.2
main.pyo(changed from APK ver.1)
2-2:'./' directory in updated APK
main.pyo(ver.2)
I tried changing the output location of the 'hello.json' file but it made no sense.
e.g. './data/data/[app_name]/files/hello.json' and './data/data/[app_name]/shared_prefs/hello.json'
How can I update my application?
Everything in the default current directory, which is named app, is deleted and replaced on app update. You can place persistent data in the directory above this, i.e. ../, and it should stick around between updates.
You can also use your app's external storage directory, using pyjnius to query the Android API for its location, but I don't have code for that right now.
This isn't especially well documented, I'll try to improve it.
Is it possible to get the config.xml file that is generated by Cordova based applications using Adroguard?
I cannot find it under the /res folder and it is not listed in the output of get_files() method.
apktool, on the other hand, is able to get the config.xml from the apk that is use it on.
Since it is under res folder, You need to get it by unzipping the file to a temporary directory and then parse it using Axml parser. In get_files(), you must see "resources.arsc" file. The res files are part of that. You can do something like :
config_xml_path = os.path.join(<your apk unzipped path>, 'res', 'xml', 'config.xml')
with io.open(config_xml_path, 'rb') as axml_file:
parsed_axml_file = AXMLPrinter(axml_file.read())
axml_content = parsed_axml_file.get_buff().decode('utf-8)
parsed_axml = minidom.parseString(axml_content.encode('utf-8'))
You might get some errors if the config.xml is badly formatted but I am not including the solution to handle those case. I hope you will get an idea with the above example.
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.
This code works in the simulator but not on my Android device:
local path = system.pathForFile("chinese_rules.db")
print("PATH:: " .. tostring( path ) )
When I run this code on my Galaxy S4 path returns nil.
My first thought was that it was some typo (case sensitivity) but I can't find any typo:
http://i59.tinypic.com/wlpu14.png
I can't find any reason why it should receive nil. This causes a problem as I can't load my database.
I have also tried this with the same result:
local path = system.pathForFile("chinese_rules.db", system.ResourceDirectory)
I have been able to load a path and load databases like this before.
Corona Build: 2013.2100 (2013.12.7)
Further reading the documentation I don't see that .db is a restricted file type:
Corona allows direct loading of images and audio files using the
appropriate APIs, but it has limited access to resource files on
Android using the file I/O APIs. Specifically, the following types can
not be read from the resources directory: .html, .htm., .3gp, .m4v,
.mp4,.png, .jpg, and .ttf.
http://docs.coronalabs.com/api/library/system/pathForFile.html
I found out the reason for the problem:
We are two that are working on this project and he had setup to use expansion files so two files was created (the main APK and the OBB expansion file) which I didn't notice and I only loaded the main APK file and I guess the database is in the OBB file. After setting not to use an expansion file the app works.
usesExpansionFile = false