Access Android USB as host OTG

I need to access the USB on an Android device from Unity and use it as host OTG to communicate with my own custom USB hardware.

  1. Is this impossible to do in Unity Indie? If so, do I need to buy both Unity Pro and Unity Android Pro?
  2. What is the procedure/framework for this?

Thank you!

In short, yes this can be done but it will be a matter of getting the Android OS to recognize your custom USB hardware. Unity won’t really be your main obstacle.

  1. You don’t need Unity Pro to do this. Unity Free will work just fine.
  2. The procedure is a little involved. You need to create a Android project with a package like Eclipse. In the MainActivity you can set up your communication with the USB device. You need to add in the Unity android library JAR file into the Eclipse project so tht it can communicate to Unity.

In Eclipse you go Properties → Java Build Path → Libraries → Add External JARs

1.On a 32-bit Windows system:
C:\Program Files\Unity\Editor\Data\PlaybackEngines\androidplayer\bin\classes.jar

2.On a 64-bit Windows system:
C:\Program Files (x86)\Unity\Editor\Data\PlaybackEngines\androidplayer\bin\classes.jar

Then you extend MainActivty:

import com.unity3d.player.UnityPlayerActivity;

public class MainActivity extends UnityPlayerActivity

Then you use this command to pass information from Java(Android) into Unity:

UnityPlayer.UnitySendMessage("GameObjectNameHere", "FunctionName", data);

If you need to pass information from Unity into Android then you have to put code in your scripts in Unity to call AndroidJavaClass and AndroidJavaObject. 1