Can we bundle a directory inside apk file? - android

I have a directory which contains some files. I want to bundle this directory inside apk file so that when I install apk file the directory gets copied to a particular location on the android device.
Can I bundle a directory inside apk file as I didn't find this information on developer.android.com? Do I need to modify any configuration file for this?
Thanks..
Ajay

You cant, but you could take a look at the android assets folder,
http://developer.android.com/guide/topics/resources/providing-resources.html
Assets are raw resources, they won't be compressed by the android compiler.
From the developers site:
assets/
This is empty. You can use it to store raw asset files. Files that you
save here are compiled into an .apk file as-is, and the original
filename is preserved. You can navigate this directory in the same way
as a typical file system using URIs and read files as a stream of
bytes using the the AssetManager. For example, this is a good location
for textures and game data.

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.

Related

Delete android file located in raw or assets directories

I make android application that read file.txt from resource/raw by context?.resources?.openRawResource(R.raw.file), and it's work fine.
I have tried assets directory by : context?.assets?.open("file.txt") and it's work also.
Now, I need to delete this raw/assets resource file or delete the content. Is there anyway to do it with android code?
No, there is no way to update the Assets or Raw files.
Both of them are read-only.
What you can do, it's to make a copy of the file in a writable directory and modify them as needed.
UPDATE
Just to give more context, both assets and any resources are part of the binary file (APK or app bundle). As they come as part of the package you cannot change them without creating a new binary.

Pack the app with some files in the data->data->files directory

I have some files that I want to read from my app.Currently, I have to do the following:
Check if the file exists in the files directory.
If it doesnt, then copy the files from assets to the files directory
If it does, then, skip step 2
So, is it possible to not copy the files ? This increases the size of my app (uselessly) as there is an extra copy of all the files.
Note, that I have to access the file using getfiles(). I am using a library that doesnt work if I give the uri of my assets folder.
So, it it somehow possible to compile the app with some files already in the files directory ?
Internal storage for you app is created when application is installed so there is no way to provide files there during compile time, that would be magic.
You could try creating ContentProvider for sharing your files stored inside assets folder.
Besides, you should tell which library you are using. Then I may be able to suggest something more precise.

How to put extra files in Android APK with Eclipse?

I want to add a text file to my APK root. This file will not be used in the application but it will stay there for manual extraction of the APK.
I tried to put it into the root of the project in Eclipse but it didn't include that file in the APK. I don't want to put it into assets folder. Can't I put it to the root?
Use the assets folder.
According to Android developer
assets/
This is empty. You can use it to store raw asset files. Files that you save here are compiled into an .apk file as-is, and the original filename is preserved. You can navigate this directory in the same way as a typical file system using URIs and read files as a stream of bytes using the AssetManager. For example, this is a good location for textures and game data.
Files that are not put into any of the main directories of your android project will NOT be included in your apk. You MUST put the file in the assets so it can be accessed within the application as an external resource/file.

Deploy a file in internal storage on debug

I am developping an Android application with Eclipse.
I have chosen to store data of my application in an XML file in internal storage.
For debugging pupose, I would like to populate this data file by hand and to deploy it in internal storage on the device.
Is there a custom folder of my projet from which files will be copied in "internal storage" location when deploying / testing the app ?
You could probably use the /assets folder of your project.
http://developer.android.com/guide/developing/projects/index.html :
assets/
This is empty. You can use it to store raw asset files. Files that you save here are compiled into an .apk file as-is, and the original filename is preserved. You can navigate this directory in the same way as a typical file system using URIs and read files as a stream of bytes using the the AssetManager. For example, this is a good location for textures and game data.
you can upload the files to the emulator using DDMS. Try this link

Android: Are raw resources stored locally on the filesystem?

I am analyzing an APK, and see a set of .txt resources in the /res/raw/ directory of the application. After installing the application on an emulator, I would expect to see those same files in the /data/data/[app]/files directory, but they do not seem to exist. Where are the raw resources stored? Are raw resources generated at application runtime somewhere else on the filesystem? Or when they are accessed, is it dynamically from the local .apk file? Thanks.
Raw resources (and really, all resources) are bundled in the APK file (this includes files placed in assets/), which is why you cannot get to the using File handles. The APK files themselves usually live in the system/app directory of the device.
The internal storage location you mentioned (/data/data/[app]/files) is where files created with Context.openFileInput(), Context.openFileOutput(), or Context.getFilesDir() are placed.
HTH

Categories

Resources