Android Services running in Unity

Hello,

I currently have an Android Bluetooth service that I have made run in the background to constantly receive serial data from my computer or arduino. This Bluetooth connection will be replaced by a sensor later.

So far, the service is working in Android, but I’m not sure how to start a Service within Unity. I have created some Unity Android plugins before, but those methods are only calling static classes.

Heres the java method that I am currently using to create my Bluetooth service:

public class MainActivity extends Activity {
	private static String TAG = "MainActivity";
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		startBTService()
	}
	
	
	
	public void startBTService(){
		Intent intent = new Intent(this, bluetoothLibrary.class);
		startService(intent);
	}

}

Now, in the Unity3D side, I’m not sure how to go about calling non-static void functions.

Any help with my problem would be great.

Thanks

Check Communication between an Android App and Unity - Jean Meyblum - Game Programer

Unfortunately it looks like its not going to be that simple. You would have to build a plugin to communicate between unity and android.

See
PluginsForAndroid

or http://forum.unity3d.com/threads/117723-Application-runInBackground-is-not-working-on-Android for a work around.

I also answered a similar question
here