Tagandroid

Easy Movie Texture For Android Version: 2.18

Whoever uses the Easy Movie Texture For Android (Video Texture) version 2.18 and also uses split apks (obbs) in unity might run into problems with the streaming asset sub-folders. It’s a great plugin to handle rendered textures on mobile devices.

However the plugin fails to create sub-directories while copying videos out of the obbs into their respective sub-folders. Which can fixed by adding

in the MediaPlayerCtrl.CopyStreamingAssetVideoAndLoad.

So it looks like this:

Also in order to have a e.g. complete callback, simply add a

in the same class and call them at the respective m_CurrentState checks:

I’ve already e-mailed the fix to Lee JaeYun and it will be fixed in a later version presumably, until then use the fix and enjoy.

Android Re-Signing Apks

In case you want to re-sign your apk with a different keystore one day you might be delighted to hear that there is a convenient shell script for this already.

It basically removes the java manifest meta file, then runs zip align and the apk signing tool of the android sdk. It naturally requires the apk, the keystore with its alias and password.

Here is the script:

In order to run it, add execution permission in the terminal:

Then simply run the script by adding the parameters.

Have fun.

Android How to programmatically close an app by pressing back button properly.

Everyone who uses apps knows that they are sometimes rather tough to exit. It’s not always because developers don’t care too much about it. Sometimes the api is tricky. If you want the user to exit your application by pressing the back button you need to override the onKeyDown method in your activity. The default implementation would be moveTaskToBack(true), which basically pauses your app and sends it to the background, right? Wrong! Because it only pauses the ui-thread.

Which means any other asynchronous task running keeps running. It wastes resources, leading to a worse user experience and and eventually to uninstalls. Why? Because it’s a unexpected behaviour. I mean don’t get me wrong, it’s perfectly fine if the app goes to the background because the user is getting interrupted by other apps. However if he wants to exit, he should have a possibility to do so. But what then?

Calling finish() often doesn’t do the trick. In that case you can use killProcess with the app process id.

Done. Just make sure that you have finished all your business before actually killing your app like saving preferences, etc. It will immediatelly close the app.

See also activitys-threads-memory-leaks

How To Get Android OpenGL 1.0 and 2.0 Information and Constrains – Revisited

Some time ago I’ve made a short post (here) about the basics of how to get opengl infos on an android device. For an app I’m currently working on it was required to get all interesting information once more in my android device information application. The basic idea is to add a respective opengl 1.1 or opengl 2.0 and possibly even opengl 3.0+ context to the active view, load all information in the onSurfaceCreate method of the renderer and remove the view afterwards again.

You’d use it appropriatelly like that in your activity:

Here is what I came up with:

Enjoy. (:

Soundlooper

Soooo Albért and Marco were visiting me the past week. They needed a couch to crash in Berlin to watch the football world championship. Congrats to Germany by the way for winning the champion ship! Anyways, Marco works as a DJ and he was playing around with his laptop to generate some random sounds. That got me inspired to create a little app over night. It basically loops through a matrix of matrices of tones and plays them that’s why the name Soundlooper. Pure creativity I know, right? xD


Continuous Integration with Maven and Travis for Android

In order to run your android unit tests automatically on external virtual server after each git commit you need a continuous integration system. There are a couple of good services e.g. jenkins and travis out there. But how do you use them? Here is one way for travis. You can start off by forking android-maven-example and adapt it to your own project. Maven’s package manager ability let’s you download and install all dependency packages. In example you also have several maven goals pre-defined. Most important ones are install – installing to a device or emulator, package – creating a jar of your libs and clean.

Now the automated tests are setup and you only need to make an account on https://travis-ci.org/ and turn on all the repositories which you want to let test.

The android maven example travis file is a bit outdated however. Android has been added as a first class citizen. So your travis.yml file could look like this:

To run the maven tests locally you can also create an emulator and run the maven goal. Note: On MAC you can also install travis-build to simply run everything by using travis run.

Create the emulator named test with e.g. API 10 and armeabi cpu.

Start the emulator. Note: No window required for first tests, if you want to tests the ui you might want to remove the -no-window parameter.

Run the test goal. Note: -e -X for showing errors and warnings in the console.

See also Travis CI for iOS.

Andorid: Free internal storage.

For everyone who also ran into internal storage shortages on android devices, clear up /data/log, /data/lost+found/ and /data/local/tmp – in my case it consumed 1.7GB out of my 2GB memory. (requires a rooted device)

Android: OpenGL 1.0 and 2.0 infos

So here I was again, trying to figure out a way to get opengl infos like max texture size, max uniform vectors, max vertex attributes, etc. for several android devices. Technically you could just use a small getter:

The problem was that on many devices the the returned number would always be 0. That’s because there hasn’t been created an opengl context yet. As suggested on Stackoverflow you could create a GLSurfaceView, add a renderer which could read the required infos by adding the glsurfaceview to the actual main active view and simply remove itself when done. In order to get opengles 1.0 and opengles 2.0 infos you would need to create two surfacesviews with different opengl versions. The following example looks a bit complicated, because I use fragments which i need to update on the main thread after I got all the infos I wanted. A full example is on github.

copy assets script for multiple resolutions for android

Assuming you want to build multiple apks for multiple resolutions on android or just have faster apk upload time to your android device during development.

Considering you want to copy from /myapp/resources/ to /myapp/android/assets/ for several resolutions and you want only to click once for each resolution build.
To accomplish this i recommend using rsycn/ and cygwin.

You might have these script files in:

/myapp/scripts/320x_CopyAssets.bat
/myapp/scripts/480x_CopyAssets.bat
/myapp/scripts/540x_CopyAssets.bat
/myapp/scripts/600x_CopyAssets.bat
/myapp/scripts/720x_CopyAssets.bat
/myapp/scripts/768x_CopyAssets.bat
/myapp/scripts/800x_CopyAssets.bat
/myapp/scripts/1080x_CopyAssets.bat
/myapp/scripts/copy_assets.sh
/myapp/IgnoreCopyAssets/IgnoreCopyAssets.txt
/myapp/IgnoreCopyAssets/320x_IgnoreCopyAssets.txt
/myapp/IgnoreCopyAssets/480x_IgnoreCopyAssets.txt
/myapp/IgnoreCopyAssets/540x_IgnoreCopyAssets.txt
/myapp/IgnoreCopyAssets/600x_IgnoreCopyAssets.txt
/myapp/IgnoreCopyAssets/720x_IgnoreCopyAssets.txt
/myapp/IgnoreCopyAssets/768x_IgnoreCopyAssets.txt
/myapp/IgnoreCopyAssets/800x_IgnoreCopyAssets.txt
/myapp/IgnoreCopyAssets/1080x_IgnoreCopyAssets.txt

Where you merely send the desired resolution at to the actually copy_assets shell script. (e.g the 768x_CopyAssets.bat)

The copy_assets.sh would look like:

And in case you want to ignore files or dirs you can use IgnoreCopyAssets.txt

Or the other resolutions (e.g the 768x_IgnoreCopyAssets.txt) Note: you can use # to comment files or directories out. ;)

Conclusion

Easy to use scripts to copy assets and remove all unwanted ones from your assets folder plus the posibility to ignore files and dirs on demand. Enjoy :)

c++ arc4random on android, windows and linux

Turns out native android development doesn’t supply you with a real ar4random method. However adapting the OpenBSD’s arc4random.c does the trick. And even works on windows without using CryptoAPI (thanks to Chris K. Jester-Young for these suggestions). Additionally with boost *ducks* it should be more or less multithreadsafe.

Mixed (red dots are generated by arc4; Math.Random() Arc4random)

And here are the convinience methods for it:

So you can use it like:

Enjoy. (:

See also