I've done developing obb function on my game app. To explain the logic of obb function simply,
makes a zip file with assets and rename as .obb.
uploads it to play store with apk. then it automatically makes an obb file
with build version code.
extracts obb file to app data folder with java.util.zip and mount to the
assets.
but if do extracting assets, it should require external storage permissions.
and it makes 10%~15% loss of customers.
Also lots of posts I've been looking for are saying permission should be needed.
but some apps like battlegroundmobile don't request access permission although it uses obb function.
So, I want to know how the apps avoid permission requirement programmatically.
extracts obb file to app data folder with java.util.zip and mount to
the assets.
Maybe that's where your problem is.
Battleground Mobile is not copying or extracting the obb file to Internal Storage. It is accessing the data stream in the file inside the OBB folder. If you just use the file in the OBB folder, you don't need to ask permission for it.
The download size is 1.53 GB. The obb file is in under Internal Storage - Android - obb - com.tencent.ig folder. Its size is 1.53 GB. So the APK size is pretty small.
It downloads an extra 195 MB update data after it starts up.
The downloaded files are stored in
/storage/emulated/0/Android/data/com.tencent.ig
Internal Storage - Android - data
which you can access via getExternalFilesDir.
Again, there is no need to ask permission to download into or read that folder.
The total app storage is 1.85GB.
App: 1.65 GB
Data: 202 MB
Cache: 10.59 MB
If you clear data, it will remove all the updates. But the content in the OBB folder remains.
Related
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.
I have a zip file. I am unzipping it to internal storage. When unzipping each file, I am keeping the same folder structure. After unzipping all levels, I want to display the files using appropriate third party apps like adobe reader etc.
I can unzipping and creating files with same folder structure. But the problem is the files could not be displayed through external app, because of permission. I couldn't set WORLD_READABLE PERMISSION, because the files are storing in custom folders. I applied setReadable also. But no hope.
How can I show files, or how to get permission to files?
Any help would be appreciated..
Thanks
Jomia
Use FileProvider to serve up the files from your app's internal storage using a ContentProvider.
Or, put the files on external storage, instead of internal storage.
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 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();
It'd be convenient if an application I'm writing stored some files to external storage permanently (so they persist after the application has been exited[destroyed]), but on an uninstall I'd like to do the decent thing and have these files removed to free up the storage.
Is there any way I can have these files removed on an uninstall?
If there isn't (and I'm skeptical), then I'll have to create these files each time. I'm trying to save start-up time and also occupy required space by having them exist permanently.
Note: I need to use external storage, so both internal storage or a DB would be inappropriate.
actually it is possible .
android will automatically remove files of the app in the external storage , but the files must be inside a specific path of the app :
"...../Android/data/APP_PACKAGE_NAME/"
where APP_PACKAGE_NAME is the application's package name.
another path that is automatically being emptied is :
"...../Android/obb/APP_PACKAGE_NAME/"
where APP_PACKAGE_NAME is the application's package name.
the data is for anything you wish.
the obb folder is for huge files that are downloaded using the play-store and the apk extension library . you are not supposed to create files there .
No, I don't believe so. Only files that you write to internal storage will be removed when your application is uninstalled (or if the user presses the 'clear data' button in the Application settings app).
Your app can't receive its own PACKAGE_REMOVED broadcast intent either, so you essentially have no notification that you're being uninstalled.
Yes, this is possible. Simply write your files to the external files directory:
File dir = getExternalFilesDir(null);
This will create a folder at /Android/data/your.package/. Note that this is not External as in sdcard, but it is publicly accessible. If a user uninstalls your app, this directory will also be removed, along with all of its contents.
Quoting from the blog post of CommonsWare
Internal storage: your file is deleted
External storage: if you wrote your file to a location rooted at getExternalFilesDir() or getExternalCacheDir(), your file is deleted. If you wrote your file elsewhere (e.g., Environment.getExternalStoragePublicDirectory()), your file is not deleted
Removable storage, prior to Android 4.4: removable storage is not officially accessible; if your file winds up out there, it should not be deleted when your app is uninstalled
Removable storage, Android 4.4+: AFAIK, if you write to a supported location (getExternalFilesDirs() or getExternalCacheDirs()), your file is deleted if that particular bit of removable storage is in the device at the time of uninstall