Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Friday, February 3, 2017

Android Video ads and WRITE_EXTERNAL_STORAGE permission

Video ads are getting more and more popular and useful for both developers and publishers. However videos require more network data and disk space to work. Many AdNetworks require external storage write permission to cache videos so that many apps can utilize it.

I just integrated Unity3D, Vungle (more AdColony, AppLovin, InMobi etc later) ad networks for rewarded videos in my game SketchVania. While testing i got issues with external storage write permission. From Marshmallow runtime permission is mandatory and WRITE_EXTERNAL_STORAGE has been added into dangerous Or higher priority permission. One must be ready to handle if permission is denied. After reading setup guide of many ad-networks i found below setting was used by many of them -


This setting means Android will allow WRITE permission upto API 18. Above this API or from KitKat no such permission will be granted. This setting comes from a very important reason. To save internal memory Android Context has methods getExternalCacheDirs(), getExternalFilesDir() etc. These methods allow app's private files to be created in external storage which are deleted after APK is uninstalled. But before KitKat these methods required WRITE_EXTERNAL_STORAGE permission. However this permission resulted into full write access to external storage. This is obviously very bad idea!. Therefore from KitKat using internal architectural changes write permission to /{EXTERNAL_STORAGE}/Android/data/{app_package}/[files,cache] was granted by default.

But there is a serious problem. I was testing my game on XIAOMI REDMI Note 3G and i found using android:maxSdkVersion="18" resulted into NO permission to getExternalFilesDir() etc methods. Whereas the Android documentation says from KitKat these methods don't need write permission. This is inconsistent due to poor or non-standard implementation by manufacturers!. It was causing IOException. This means if you are using maxSdkVersion="18" then chances are high on many Android 4.4 or 18+ API devices using getExternalFilesDir() like methods may not work. In my game i was saving game stats in this directory and nothing was getting saved!. Solution is to simply avoid using max sdk version and use internal cache and files like getCacheDir(), getFilesDir(). However this issue was fixed and most of ROMs today allow access to getExternalCacheDirs() etc without write permission. You may want to dynamically check write permission and handle files. This issue is a lesson that depending on manifest settings can be problematic in future.

Monday, June 27, 2016

Android app to extract soundfont (SF2) from sfArk

Decades ago Soundfont files were packed to reduce their size to manage for storage limited devices. Many developers came up with tools to compress SF2 files. Major of them are sfArk & sfpack formats. Now we have lots of space and those formats are mostly abandoned by their makers. Also the software support from 3rd party is almost dead. Some PC apps like Polyphone support extraction of sfark and sfpack files.

I have ported unsfark & sfArkXtm to Android which handles both sfArk formats. Simple advice is to just stay away from these formats. Convert them to sf2 files and use latest methods to compress them or use sf3 if supported.

Android sfArk extractor port link:

It detects old sfArk (unsfark) & new sfArk (sfArkXtm) and extracts sf2 to destination directory. If you are a developer and you need source of android lib files please mail me i will either upload here or mail you. There is not much of changes done to the code.

Extracting shockwave flash (swf) files in Android using swfextract unofficial Android port

I have been porting some non Android apps to Android. Among them latest one is swfextract program. Do you have swf files from which you want to extract audio/graphics etc assets? You lost .fla files and want assets back? Or do you want you favorite music or graphics out of swf file?

If above is your need there are swf extractors. swftools is a collection of such tools. But swfextract is the app which extracts assets out. Below is the link of Android port of this app which can very easily do this job.


It can extract many files at once. It creates swf named folders and extracts data into it.