In Flex, How to access packaged file in apk? - android

I am building an android app using FlashBuilder and is using a sqlite database, and the initial database shall be packaged into the apk (Android package). When the app runs firstly, the packaged database should be copied to "applicationDirectory".
However, problem comes.
I can use File.applicationStorageDirectory.resolvePath("xx.db") for the destination when using File.copyTo() function. However, how about the file to be copied (from the apk package)?

Can you be more specific about the problem. Is it that you are getting an IOError when you try to copy a file(db) from the application directory to the app-storage directory? Have you checked the contents of the packaged apk? Why dont you consider creating the db in the app-storage directory when the application starts because that application directory is quite protective of its content.
What are you trying to achieve really?
P.S. Keep in mind that the Application directory is read only. So your code cannot write files that reside on that directory.

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.

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.

Are user-defined directory names allowed in an Android Eclipse project

I think I may know the answer to this question already, but I just wanna be 100% sure. Anyways, I am writing an Android app using Eclipse 4.2 ("Juno"). I want to create my SQLite database by using external files and reading/parsing these files by my code. Hence, I created my own directory called /database and placed it in my project's root directory. Then, Eclipse starts complaining, reports a problem and says:
Invalid recourse directory name.
I even tried placing my database directory in the existing /res directory, but that caused the same Eclipse problem. Just want to confirm what my initial thoughts are: Is it not allowed for me to define my own directories in the project and bundle it in with my release?
If so, then I guess I'll have to follow along with what was posted in this stackoverflow question.
put it in /assets not in /res and it should work.
You should be able to create arbitrary directories in the root of your Android project, however your application won't be able to access these files. This is useful for development purposes like storing test data, documentation, or jar files. However, you cannot create non-standard directories in places like gen and res.

Android - add files into APK package?

is it possible to add to my apk file some XML file storing program version, update path and other useful data (note: I don't mean Android XML file). All I want to is this file to be unpacked somewhere to local data folder and I will use it for comparing version info installed locally and on the server in case of updates.
I am asking - is it possible to add to apk some other file?
Thanks
The assets/ folder in apk is intended to store any extra user files in any formats. They will be included to apk automatically on compilation stage and can be accessed from the app using getAssets() function. For example:
final InputStream is = getResources().getAssets().open("some_file.xml")
It is even unnecessary to copy them to some local folder to read them.
If you only want to know the version info of the app then there is a much easier way to identify it. You can use
getPackageManager().getPackageInfo(getPackageName(),PackageManager.COMPONENT_ENABLED_STATE_DEFAULT).versionCode
to get the version code and
getPackageManager().getPackageInfo(getPackageName(),PackageManager.COMPONENT_ENABLED_STATE_DEFAULT).versionName
to get app's version name

Categories

Resources