Read/write from Android/data folder with Flutter - android

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

Related

Importing and exporting files from flutter app on mobile devices

Developing an application with database backend (sembast) I ran into an interesting question:
What is really (I mean REALLY) proper way to work with files in flutter.
Long must read
Having database I want to: import files, export files without too much fuss from/to local file system.
Now as I get it there is a "user space" on android (minSdkVersion: 21) that is accessible and everything outside it works on some SDK version, not all of them.
Issues by numbers:
There is no reliable way to get "Downloads" dir for all platforms (at least mobile ones).
What's the point exporting to /data/user/0/app_name/bla-bla-bla if we can't read it with file explorer?
Import from /storage/emulated/0/Download just fails with no permissions. (That's considering my Manifest has READ/WRITE_EXTERNAL_STORAGE).
Now I wonder, if there is a way to export json file somewhere on file system from where I could later import data to app with no permission issue? Ideally it would be great to have a class or module that delivers cross platform set of locations.

How create folder (and file) within the installation of app in Android?

I want to create a folder with pictures just in installation.
I searched a lot for this but I didn't found nothing but a lots of apps do that. I speciffically mean the Android folder in /storage/emulated/0/ or /sdcard/.
That is not possible, sorry. You are welcome to create directories and files when your app is run by the user. There is no option for doing so just because your app is installed.
you can create the folder after the app is installed.. However you can design your code such that it creates folder while loading the Application for first time.

KIvy Android how to create and read a file

After looking all over google I haven't found a way of accessing Android internal storage from python.
I need to store an image generated by kivy app. I would like my python code to be able to navigate to a root user dir, create an app specific dir (if not found) and save the image there.
Simply creating a file with my device's path doesn't work. Should I be setting permissions for internal storage access? I'm lost with it.
You have something wrong in your code, you didn't paste the code nor logs, so... let's get it another way.
You can read/write with python just fine in the app folder (/data/data/org.something) with using:
app_folder = os.path.dirname(os.path.abspath(__file__))
To write to SD card you'll need to use App.user_data_dir, which as you can see in the docs on android gets you /sdcard/<app_name>. Not sure if it automatically creates it if it's missing, so it needs checking out probably. However, if it doesn't exist, just create it with python:
os.mkdir(App.user_data_dir)

Associate a folder to an APK

In the app I was helping developing, the users seen that each time they use apps like CM Security to clean 'junk', the files inside the folder associated with the app were instead considered as 'junk' and are deleted.
The app itself would create the folder in the C side of the code instead of using Java.
Firstly, when the app is first launched, custom C code will check if the app folder (e.g. 'Game') exists. If it doesn't, it makes it (regardless of OS. The app is cross-platform, sorry I forgot to say it.) It puts it in the external SD card ('sdcard/'). When it's seen, it can now run the app.
I get about the getFilesDir, but since the directory is made using C code and not through the java activity, it doesn't count as its app directory.
Is there a way to link the folder to the Android code so that it would be recognized as the app folder?

Access internal files after built - Cordova

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.

Categories

Resources