My project have multiple files in SD card. But when I install apk file on phone it does not work.
Please tell me how to attach those files with apk.
Your sdcard files cannot become the part of APK file, if you want those files to attach to your apk, insert them into asset folder or raw folder.
EDIT:
If you put your file in raw directory then:
com.your.package:raw/yourFile
Like this:
int resourceId = context.getResources().getIdentifier("com.your.package:raw/somefile.txt");
File f = new File(context.getResources().openRawResource(resourceId));
And here's someone doing it with the assets folder:
Android Assets with sub folders
InputStream is = getAssets().open("subfolder/somefile.txt");
Create a sqlite database and store the path of whatever files you want to store on the sdcard. Also you can store them in assets folder depending upon the type of file but it is not a good practice as many say.
You could store the supporting files on a web server and have the application download the files to the sdcard on first run. This is what many games do. Google Play also offers free storage of files for applications.
Here is the Google blog post on large APK's
http://android-developers.blogspot.fr/2012/03/android-apps-break-50mb-barrier.html
Related
I am new to android expansion files. I am not sure how it works or what to do (step-by-step build) an expansion file. As far I been reading, if I am not wrong please correct me; expansion files can be files that are stored in the Asset folder or Res folder. What I don't understand is if my app is depended on files that are stored in both folders and I take them out wouldn't that cause an error build? How does expansion really work? Furthermore, If I successfully create an expansion file from res folder (example) would the expansion file store it in the res folder in the phone? or I have to change all my code that makes reference to the res/drawable folder to the appropriate location? If so, then what is the correct path that I need to change my code into?
My app is so far like 600mb and continue to grow. Within my app, the core dependance is a database stored locally in the asset folder and some images in the res\drawable folder. There are some images that are not dependance on the app directly which makes the remaining 550mb. Nevertheless, those images are needed because the database makes reference to those images (just the name) then I populate an imageview with reference from the database. I was thinking to store all those images into an expansion file but I was not sure if those images will be store within the res/drawable folder in my phone or it will be store in a different folder? if so, would that cause an error?
The expansion files are not supposed to save in your res folder. Res folder is part of your APK, so if you save your extra images in the res folder, your APK will still be over the 50MB limit.
From the Google Developer page, it states that "The expansion files are saved to the device's shared storage location (the SD card or USB-mountable partition; also known as the "external" storage) where your app can access them. On most devices, Google Play downloads the expansion file(s) at the same time it downloads the APK, so your application has everything it needs when the user opens it for the first time. In some cases, however, your application must download the files from Google Play when your application starts."
So, your expansion files should be saved in SD card. You can zip your images into a zip file, stored zip in your SD card, and read them while your application start.
You can use the APK expansion Zip Library and read the file from the zip. Sample code from Google Developer page:
// Get a ZipResourceFile representing a merger of both the main and patch files
ZipResourceFile expansionFile =
APKExpansionSupport.getAPKExpansionZipFile(appContext,
mainVersion, patchVersion);
// Get an input stream for a known file inside the expansion file ZIPs
InputStream fileStream = expansionFile.getInputStream(pathToFileInsideZip);
You can read this documentation for more information about APK Expansion file.
You can also find some tips from the Android developer blog about the APK Expansion file.
Or you can visit this APK Expansion file tutorial.
I am really new to android devices, we have got an app that needs to read a *.cfg file from the same place as the apk. So the question is:
1) When i attach my mobile-phone to the computer, can i put it from the explorer? If yes, how?
2) Is there a mechanism in Android, that looks for some kind of include directories
when opening a Program?
It would be great if you could give me a hint.
You'd want to drop the *.cfg files into the assets/ folder. Then the app will have access to those raw *.cfg files during runtime.
From Managing Projects
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.
I'm working on an Android application that needs to store media (document files like pdf or so for later reading) but the main requirement is that all media files have to be accesible through an absolute path (a physical path on filesystem).
I'd like to avoid copying files to external storage (like sdcard or phone internal memory) so to prevent that if application is uninstalled those files remain in phone (and of course to avoid duplicating the size in kb for each file) and instead to keep files in iny App internal resources folder, but tried "file:///asset_folder" whith no success. As far as I know "file:///asset_folder" only Works for a webview to Access www folder but not for regular files.
I'm not sure if there is any app internal data folder which I can access through an absolute path or if not which is the best way to store App resource files.
Thanks in advance!!
Edit: To make it more clear, the resource files are already bundled with the App, and not written during runtime, and what I'd like to know is where to put them so I can later Access them via absolute path for Reading.
To retrive your app specific data
openFileInput(file_name)
To save your app specific data
openFileOutput(file_name, Activity.MODE_PRIVATE)
Update : Read from asset folder. (InputStream)
getAssets().open(fileName);
getAssets().open(fileName, accessMode);
check the image to where to put asset files
now to make other app readable your files from private data/data directory use content providers.
You can not write data inside asset_folder because it is packed on apk file. You can use sd card or location where your app is installed inside internal memory.
i am creating an app where i unzip the files and load it to SD card but instead i wish to load them to the assets folder on the project. How to do this can any one help me with this
You cannot write into your Apps Asstes Folder.
Use data/ on SD Card or for small things the SharedPreferences instead.
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?
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-file:
InputStream is = getAssets().open("path/file.ext");
To list a directory:
String[] files = getAssets().list("");
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);
It is worth mentioning that really large amounts of data can be dealt with APK Expansion Files.
In 2016, Google Play currently requires that your APK file be no more than 100MB. For most applications, this is plenty of space.
The APK size limit increases from time to time, so it's meaningful to check the current digit.