Does assets/ folder reside in device's RAM? - android

When I launch the app, where do the assets/ folder contents go?
Are they loaded into RAM?
Or maybe AssetsManager always reads from inside /sdcard/?
Am I safe to assume that any Android device handles assets/ folder in the same manner?
My concern comes from the fact that some devices that I target are very limited in the amount of RAM they can provide, while all of them have a decent /sdcard/ storage, therefore I must decide if the assets should be downloaded at runtime or if they can safely be included into the apk file.

Assets are not saved in the "external files" directory (a.k.a the SD card). They're saved in the main app storage.
You can encourage your app to be installed on the SD card via android:installLocation="preferExternal". Your app will use this less valuable storage for everything, not just assets.
To have just assets on external storage consider expansion files like #pskink mentioned in a comment, or downloading them yourself and caching them in external storage.

I have successfully launched a 587 MB application on a device that comes with 512 MB available RAM, so it turns out that at least some of the devices indeed avoid pulling the whole assets/ folder to RAM upon launching the application.

Related

Any reason to use external storage on Android anymore?

Early on, Android external storage (as available via Environment.getExternalStorageDirectory()) actually stood for the physical removable card. My application goes back to 2011. When designing it back then, I made a point to place any potentially large files in the external storage, to save the precious device space.
These days, I don't have a large fleet of devices, but on all that I see the external storage is physically internal, not removable. Can't tell, though, if it's in the same filesystem as the data folder (as in Context.getDir()), i. e. are they under the shared space constraint.
Anyway, the question is - in 2019, does it still make sense to place large files into external storage as opposed to the data folder?
Anyway, the question is - in 2019, does it still make sense to place large files into external storage as opposed to the data folder?
The documentation covers why you would want to put things in internal or external storage depending on your use case:
https://developer.android.com/training/data-storage/files#InternalVsExternalStorage

Where do you put downloaded filed in android

My application downloads files from the server and save them somewhere. Where should I put the folder to save the files? Not in assets right? Should I create a folder somewhere parallel to "bin"/"libs"/"res" folder?
Another question: should I put the downloaded files in internal storage or external storage?
Actually you can not save the downloaded file in either of this folders because they are not allowed to make modification at run time.
Best option goes according to your requirement, as if you file is too large and you are not much worried about it's security then you can store them on SDCARD(External storage). and if your file is small enough and much secure then you should save them on internal storage.
Check most popular application store their files on SDCARD but encrypted way...
Hope this ans your question
Store your downloaded files in a folder on an external storage directory. like
String yourFolderPath = Environment.getExternalStorageDirectory() + /com.yourapp/;
Store files in that folder.
if its just few files, it would be safer and more convenient to use the context.getCacheDir(). with it, you can be sure that it will always be there unlike sdcard which can be locked when the phone is in storage mode. it doesnt require manifest permission. You don't even have to worry about security unless your user is rooted.

Android Tablet Internal Storage

1)I am converting an ipad project to android.In doing so,in ipad
version ,I can save the internal files in bundle (called Bundle
directory) and all the files are stored under Documents which is
internal to app.
In android we have /data/data/{package name}/files
My Question is I should be able to store large data inside the
internal storage.Does tablet have large internal space(atleast latest version) ?I dont want to save the files in sdcard either because it can be replaced or something.
Is the device RAM used for internal storage of files?I am facing a memory problem where as in ios we can have sufficient data stored in application sandbox...I need to copy files from assets to in internal storage during run time(by files I mean large files).
Can somebody throw light on this.Thx in advance
Internal storage is separate from RAM in android.
The amount of internal storage varies from device to device
Its not entirely uncommon to copy large assets (like pre-made databases) onto the tablets internal storage for applications to function properly so it shouldn't be a problem for you.

Way to save application cache in internal sdcard in android?

In my application , downloading lot of files from server. I want to cache them in sdcard.
for that am using fallowing api..
context.getExternalCacheDir();
But problem is that, not able to save them in internal sdcard(i.e; non removable external storage).They are saving in to "/mnt/sdcard/external_sd/Android/data/".
Please gimme a way to save may files in to non removable android cache.
Regards,
Srinivas
From intellisense for Environment.getExternalStorageDirectory:
"Gets the Android external storage directory. This directory may not currently be accessible if it has been mounted by the user on their computer, has been removed from the device, or some other problem has happened. You can determine its current state with getExternalStorageState().
Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.
In devices with multiple "external" storage directories (such as both secure app storage and mountable shared storage), this directory represents the "primary" external storage that the user will interact with.
Applications should not directly use this top-level directory, in order to avoid polluting the user's root namespace. Any files that are private to the application should be placed in a directory returned by Context.getExternalFilesDir, which the system will take care of deleting if the application is uninstalled. Other shared files should be placed in one of the directories returned by getExternalStoragePublicDirectory(String)."

Assets on storage card

I have an application that stores a lot of data in the assets folder (html, audio, video, etc.). I use the file:///android_assets to access these files. But due to the apk size limitation of 50 MB imposed by the market I will be migrating these files to a storage card.
Is it possible to install the application on phone memory and have the assets directory on the storage card, so that they can still be accessed using file protocol?
Since assets are part of your apk, it's not possible to separate them or move them to the sdcard. You can enable "Move to SD Card" for your app, but that doesn't help with the 50 MB market limit.
One solution would be to store the data files on the web and not include them in the apk. When your app is launched for the first time after installation, you would kick off a one-time process that downloads them to the sdcard.
Once the files are on the sdcard, you can access them with:
file:///sdcard/<your_directory>
Or to get a File reference to the sdcard root directory:
File sdCard = Environment.getExternalStorageDirectory();

Categories

Resources