Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include data files with the app's APK?

I want to create some pre-created files when my Android application is installed.

I would like to create the file in both the internal memory (data/data//files/) and in a newly created sdcard directories (/sdcard//data1/).

How can I do this?

like image 297
Xarph Avatar asked Nov 30 '10 05:11

Xarph


People also ask

How do I put files on APK?

If your phone's web browser doesn't give you the option to open the file after downloading, open your file explorer app, go to the Downloads folder on your device, then tap the APK file. Allow the app any required permissions it asks for. Then, at the bottom of the installer window, tap Install.

Where is data stored in APK?

apk? For normal apps, there are stored in internal memory in /data/app. Some of the encrypted apps, the files are stored in /data/app-private. For apps stored in the external memory, files are stored in /mnt/sdcard/Android/data.

Can Android apps access app data?

On devices that run Android 9 (API level 28) or lower, your app can access the app-specific files that belong to other apps, provided that your app has the appropriate storage permissions.


2 Answers

If you have a larger number of files and a directory structure you should use /assets. These are not given any R-constants and can be scanned by your application

To open an asset-fil:

InputStream is = getAssets().open("path/file.ext"); 

To list a directory:

String[] files = getAssets().list(""); 
like image 71
Mikpa Avatar answered Sep 28 '22 13:09

Mikpa


You can save you files in \res\raw and write the code to store this files to the desired locations if it does not exist when the app start.
Check this to access the internal memory and sdcard
and access the raw file using the following

InputStream databaseInputStream = getResources().openRawResource(R.raw.yourfile); 
like image 45
Labeeb Panampullan Avatar answered Sep 28 '22 12:09

Labeeb Panampullan