Last active
November 27, 2016 06:40
-
-
Save flushpot1125/47c7cb56bd156593badcefcca2a80827 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.microsoft.CognitiveServicesExample; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.util.Log; | |
import android.content.ServiceConnection; | |
import android.content.ComponentName; | |
import android.os.IBinder; | |
public class NativeBridge { | |
private static MainActivity m_MainActivityService; | |
private static boolean mServiceBound = false; | |
private static ServiceConnection mServiceConnection = new ServiceConnection() { | |
MainActivity myBinder; | |
@Override | |
public void onServiceConnected(ComponentName componentName, IBinder service) { | |
MainActivity.MyServiceLocalBinder myBinder =(MainActivity.MyServiceLocalBinder) service; | |
m_MainActivityService = (MainActivity) myBinder.getService(); | |
mServiceBound = true; | |
Log.e("Unity", "Service connected: " + myBinder); | |
} | |
@Override | |
public void onServiceDisconnected(ComponentName componentName) { | |
myBinder =null; | |
mServiceBound = false; | |
Log.e("Unity", "Service disconnected"); | |
} | |
}; | |
/*These three functions are called from Unity*/ | |
public static void startBindService(Activity unity) { | |
Intent intent = new Intent(unity, MainActivity.class); | |
unity.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE); | |
} | |
public void startRecognition(){ | |
m_MainActivityService.StartButton_Click(); | |
} | |
public static void stopBindService(Activity unity) { | |
if (mServiceBound) { | |
unity.unbindService(mServiceConnection); | |
mServiceBound = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment