Skip to content

Instantly share code, notes, and snippets.

@nipundavid nipundavid/Controller.cs
Last active Jul 22, 2017

What would you like to do?
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("");
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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.