I am wondering if is possible accessing the internal files of an app after build with cordova plugin.
My project is based on Android and here are my files:
index.html
html:
- remove.html
js
css
So, after build the app, I want to access with some option within the app the remove.html and remove it.
I find that the FILE plugin of cordova is useful for files inside the device but not the app.
Please anyone has any idea?
we do not have modification access to the location where apk's internal files are saved. Since your remove.html is part of your app apk, we cannot just remove it.
You can take the same approach taken by sqlite raw database file. When your app is started or run for the very first time, copy your file (remove.html) to data folder where you can modify/delete it. Make sure your app only uses this new path everywhere.
Take a look at copyDatabaseFromAssets function in this code for a sample on how do this. Since you will have modification access, you can delete or modify this file as needed.
Related
I recently decided to experiment a bit with flutter and Android development, and I'm trying to create a simple app to import and export a game saves (because you can use the file both on Android and PC, but there isn't an official sync system yet), but I'm having troubles with file management. Basically, what I would like to achieve is the following:
Export: the app should copy a file from the Android/data folder of the game to another location (example: download folder)
Import: the app should let you pick a file and then copy it to the data folder of the game
Right now I managed to ask for both storage and manageExternalStorage permissions when launching the app, but even with those I get an access denied error (errno = 3) when trying to export the file.
Is it even possible to achieve my goal? Or maybe I'm just doing something wrong with permissions?
I'll give more info about the app (for example code snippets) if you have specific requests on some aspects of it
Is it possible to automatically write my own config files upon installation of an APK? How do I do that? I realize this might introduce unwanted bugs as user can change these configs. However, I need this functionality in my Android app. I don't want the application to run first then write the file. What I really want is writing my own config files upon installation. Can anybody give pointers? Thanks.
What I really want is writing my own config files upon installation.
That is not possible. There is no hook in Android to automatically set up some sort of files on internal storage. And, if you are "writing [your] own config files", then by definition, then "the application [will] run first", because your application is where the file-writing code resides.
Configuration files? If its related to the APK of your app then chances are, it is gonna be the run first then write the file. A thing for writing file though is the assets folder that an android project has.
I have an offline application cordova, composed of simple html and pictures, all inserted in a sub folder (android_asset/www/app). I would like to add a second online application (android_asset/www/update/) that, check for update, download and replace the first. Is this a reasonable solution for in app synchronization?
Thanks for the time
cordova-app-loader is an easy to use plugin to update app files via 3 simple steps:
check() for a new manifest
download() files
update() your app!
It supports android and iOS
You could achieve desired functionality if you will use Cordova File Plugin.
Main trick is to load files not from android_asset/www/app, but from location on the phone storage, using cdvfile protocol (which point to the file location on the phone SDcard).
When you application starts first time, you will go to you server and save latest app version to the phone storage, and then launch you app logic code from there.
When you check for updates, you download new files to you app location and next time application will use these files.
Cordova Hot Code Push plugin also seems to address that matter. Its code seems much cleaner than cordova-app-loader and easier to use.
I am using Phonegap to develop my app, so I need to package CSS,JS,JS libs, index.html to assets/www folder, and
super.loadUrl("file:///android_asset/www/index.html",4000);
but is there's a way to update my CSS,JS,JS libs, index.html without updating my app(NOT update apk file wherever from store or our own server) -- this is because some page I need to be interactive with native and it(CSS/JS,index.html) may need to be changed .
Sound stupid, but is there a way to satisfy this requirement, and how about iOS solution?
I've read from this : cannot modify the files in /android_assets/www with the File API , can't get a file object from an asset
However , I found copy files in assets to sdcard.
So, can I update the assets files , in some way ? or this sound stupid way(I don't know iOS solution):
1 copy it to sdcard
2 update the css/js/index.html
3 super.loadUrl("/mnt/sdcard/myapp/index.html",4000);
Is there other solutions, THX ?
For Cordova/Phonegap it's available, a contentsync plugin for download remote resource and update application assets or Cordova plugins without store republishing.
Check here: phonegap-plugin-contentsync
So, I'm developing an app that requires a prepopulated database. According to Raymon Camden, there's no direct way in packaging a pre-made database with the app. As a solution, I'll execute a Select count(*)... statement to check and insert if result <= 0,
Now problem is the insertion. I have ~500 rows for a table, and I don't want to paste them in the js file. I found the File API and I believe I can read the .sql file, then execute.
Questions:
How does PhoneGap 3.1 (ugh, naming.) package apps? In my www directory I have
js
css
dev
data.sql
So, initially I thought fileSystem.root.getFile('/dev/data.sql', ... would work. (Basing on this, where MattDavis said app data goes to /data/data/packageName.)
How do I access the file?
Am I on the right track? Or, is there a better approach?
I am using Cordova 3.1 to build, with the awesome support of Netbeans.
EDIT
I tried creating a .txt file on the root dir of my device. I can successfully access it with fileSystem.root.getFile('test.txt', ...). And so I infer that I simply need to get the actual app directory.
Yes, your in right track only. Because your access with in asset/www/dev/ inside data.sql.
/data/data/packageName this is for accessing SD inside your app (app internal storage). so no need do like that.
How did I access the file? + Or, is there a better approach?
AJAX. It turns out that I can access the assets folder through:
$.get('file:///android_asset/www/dev/data.sql', function(response){
console.log('Data found!');
console.log(response);
});
I am not sure if this'll work with other platforms.