How can I use files in my Android application written in Rust? - android

I'd like to have additional assets shipped with my Android application, which I'm programming in Rust (using cargo apk from android-rs-glue).
How can I access a directory
with files which will be placed there during the installation
which is optimally local to the application (isn't there some "data" directory)
or achieve something similar where I can read a file (for example say a .obj file with some game models) without embedding these files into the source code
?

Related

Is it possible to include internal/external storage directories such as the Android Downloads or Documents folders in the Gradle Source Sets?

So I am developing an Android App that incorporates a Python Interpreter, one from Chaquopy, and one of the requirements inorder to run any scripts is for the .py files with the code to be included or rather be in any of the default or predefined source set directories/folders. This works well if the .py files are included/bundled in with the APK file but this presents a challenge in that the files now become read-only files at run-time since they cannot be modified when the app is running or has been installed.
The app is to allow the users to create, save code, and read from .py files that they would have created, but then the challenge now is that the files will be included in the directories such as the Android Downloads or Documents folder or the apps' internal files folder and as such they cannot be run in the application since it requires that they be saved in any of the source set directories, as the interpreter will look for them there.
I have tried to incorporate the 3 directories in this way, using their respective paths `
sourceSets {
main {
python.srcDir "/src/main/assets" //this works for asset files, the rest don't
python.srcDir sdk_gphone_x86/storage/emulated/0/Android/data/com.tendaik.chaquo_trial_2/files"
pyrthon.srcDir "/storage/emulated/0/document"
python.srcDir "/storage/emulated/0/Android/data/com.tendaik.chaquo_trial_2/files"
python.srcDir "storage/emulated/0/Android/download"
}
`
But all to no avail unfortunately, as this only succeeds in creating and including these directories in the project as project directories instead of accessing the directories from the internal storage, as shown in the image. All premissions to access the folders/directories are included in the Manifest file as well
How then can I include the internal storage directories as part of the source sets, if it is possible?
You can't list Android device paths in the build.gradle file, because that file only controls the build process: it has no effect on the runtime value of sys.path.
However, there are various ways you can dynamically load Python code at runtime:
If the code is in the internal storage directory, then you can simply add its location to sys.path.
As it says in this FAQ, the external storage folder (which contains Downloads and so on) cannot be accessed directly in recent versions of Android, so adding it to sys.path won't work. Instead, by following the example in the FAQ, you can use the system file picker to get the content of any file, and then do whatever you want with that content, such as passing it to exec.

Unity - files .txt in Project are hidden into the .apk?

If I have a .txt file in a project folder of an Android project and I build this project as .apk. This file is accessible for the user from the Device Explorer or in hidden into the .apk?
(I apologize for my english)
You can also access the streamingAssetsPath (read only):
https://docs.unity3d.com/ScriptReference/Application-streamingAssetsPath.html
and the persistentDataPath (this is a folder where you can read/write data, accessible to your users... but you can access this folder only after the installation):
https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html
To read files in the streamingAssets on Android you need to use WWW class but everything is explained in the docs (with an example).
Read this to understand if you really need to use Resources folder or it's better to use streamingAssetsPath:
https://unity3d.com/learn/tutorials/topics/best-practices/resources-folder
if you want to undestand the difference I suggest to read this:
https://forum.unity.com/threads/resources-vs-streamingassets-for-mobile.494804/
Unity will produce a .apk-file.
Your .txt-file will be baked in if:
Its referenced by something in the scene
Its in the Resources folder

Using a linked file in Assets directory - FileNotFound Exception

I am trying to link to an external file from a shared repository between my iOS and Android apps. This does not present a problem for iOS, but it does for Android. My current solution is to create a copy of the file from the external repository and place it in my projects Assets folder. This solution works, but is not much of a good one in my opinion and involves too many extra steps.
Using Eclipse, I am able to link to a resource. It's as simple as copying a file into my Assets folder and being prompted to either copy the file or link to the resource. If I link to the resource and try to run my app, I get a FileNotFoundException. If I copy the file instead, the app file is found just fine.
Ideally, I'd like to link to the file so that when I pull a new update from git then I don't need to copy the file over every single time. I'd prefer to link to the file.
I don't know what Eclipse uses "under the covers" for "Link here" drag-and-drop stuff. However, it is an Eclipse-ism. Android's build tools are fairly isolated from Eclipse proper, and so they won't know about those links.
Using a hardlink, or perhaps a symlink, at the OS X filesystem level should work, as both Eclipse and Android's build tools should treat it like a local file.

Phonegap 3.5.0 Cordova Access to application folder after build app

After building the application using Phonegap Build for iOS and Android, we want to update some files from online to local application files, i.e. we want to download images from online to the images folder into the application.The application contains folders like the below: js/, images/, css/,.... So using cordova File API, the fileSystem.root.fullPath returned the '/', base root of Files stored on the device, i.e. /Download, /viber, /media, /Pictures, /WhatsApp, .... Also, the cordova.file.applicationDirectory returned the application directory of the istallation, which not included the files of the application!
The question is how to proceed to get access to the root of images folder into the application? The application read from images from images folder, so we need to update files into this folder...
Thank you for your cooperation.
The application folder itself is read-only (as the File plugin says on it's documentation) as it is the installed package. You can access it with the cordova.file.applicationStorageDirectory on Android and cordova.file.applicationDirectory on iOS with appending the correct path such as www/images/ after it.
You want to store your downloaded files to somewhere like cordova.file.externalDataDirectory on Android and cordova.file.documentsDirectory on iOS and then use those files within your application.

Read txt file in res/raw/ within Android NDK

I have a file within my application that I want to have included within the .apk for my android app that is a .txt file. My application is almost entirely written in C through the use of the NDK, using OpenGL as well. I know I can bundle the txt file by placing it in /res/raw/, but is there anyway I can access this within the android NDK?
-Thanks
See the native-audio sample in the NDK. This has code that reads from the assets folder.

Categories

Resources