Tuesday, November 19, 2013

Unity Plugin Android(Part2)

In my last post iv'e covered about how to write a plugin without actually over-riding the unity activities so you can peacefully co-exist with other unity plugins (for android).

The reality is that you will have to deal with people using Prime31 as one of their plugins. This can be a problem if you need to get callbacks for the android system event callbacks like:

void onCreate(Bundle Intent){

void onStart(){

void onStop(){

and so on. You get the idea. Fortunately the prime31 guys provide us a method for registering a class to get callbacks from these methods on the activity. The details of which are provided at the following url


This is pretty straight forward If you know how to use Android ADT/Eclipse for creating android projects. Here is how you go about it.

1) First create an Android Project. Mark it as a library project.
2) Add unity-classes.jar file to the libs directory of your project.
3)  Create a java class with the functions you want callbacks on.  Say you want callbacks for onCreate, onStop and onStart then here is the class you have to write:
Once we have written this class,  Right click on the class name and click on Copy Qualified Name. In this example the qualified name is "com.tms.shivaproject.AdRefActivity"

2) Edit the AndroidManifest.xml file to specify our class as the meta-data for the Prime31UnityProxyActivity with the following
3) The last part is to just build and launch. You should see the logs in the logCat.

Note: This tutorial assumes that you know how to create a jar file from an android project.