Last active
July 22, 2017 16:49
-
-
Save nipundavid/55aa1e8600c2aced7e3dc0d0a8378672 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
using UnityEngine; | |
using UnityEngine.UI; | |
public class Controller : MonoBehaviour { | |
// To display output of the alert box | |
public Text reply; | |
// To store context of the main activity that Unity3D is running | |
private AndroidJavaObject activityContext = null; | |
// To store the instance of the class | |
private AndroidJavaObject nativeDialogBox = null; | |
void Start() | |
{ | |
AndroidCallBacks androidCallbacks = new GameObject("AndroidCallBacks").AddComponent<AndroidCallBacks>(); | |
// Get MainActivity class instance that Unity is running | |
using (AndroidJavaClass activityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) | |
{ | |
// Get context of the MainActivity class that unity is running | |
activityContext = activityClass.GetStatic<AndroidJavaObject>("currentActivity"); | |
} | |
} | |
public void ShowNativeDialogBox() | |
{ | |
CallNativeDialogBox("Dialog Box", "This is a Dialog box", "Yes", "No"); | |
} | |
private void CallNativeDialogBox(params object[] args) | |
{ | |
AndroidJavaObject bridge = new AndroidJavaObject("com.plugin.android.dialogboxmodule.ShowNativeDialogBox"); | |
activityContext.Call("runOnUiThread", new AndroidJavaRunnable(() => | |
{ | |
bridge.CallStatic("ShowDialogPopup", args); | |
})); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment