- Download DeployGate SDK ( https://deploygate.com/docs/sdk#install ) and extract
- copy deploygatesdk.jar into YOUR_PROJECT_ROOT/Assets/Plugins/Android
On your app startup, install DeployGate into your process:
// Get Android context
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject app = activity.Call<AndroidJavaObject>("getApplicationContext");
// Install DeployGate, make sure it will not called twice in your app
AndroidJavaClass dg = new AndroidJavaClass("com.deploygate.sdk.DeployGate");
dg.CallStatic("install", app);
// OR if you want bit more secure (with provider account name) try below:
// dg.CallStatic("install", app, "YOUR_DEPLOYGATE_USERNAME");
DeployGate#install() work asynchronously. May need some time to initialize, within a second in most case.
After that, at the point of check authority, write the code like this:
// Check the app is authorized (this will block until finish the initialization above)
bool isAuthorized = dg.CallStatic<bool>("isAuthorized");
if (!isAuthorized) {
// quit the app
}