- Home /
How to make Android Plugin for Unity3d
I am trying to build Android Plugin for Unity3D. My Android Project is a Library project and i have used it on different Android Applications. This Library project simply displays a Dialog on my Main Application, having some images. An xml layout is attached to this Dialog to set Image placements.
Now I want to use the same Android Library Project with Unity3D. I have followed a simple tutorial that lets me communicate between Android and Unity3D.
So in Unity3D using AndroidJavaClass, when I call this function to display the dialog containing images, it shows nothing and with no error.
Is there something I should change in my AndroidManifest or what should I change in my code to display this dialoge?
Please Help me out of this.
Update-1
This is the code on Unity3D side this is the bridge Class.
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour
{
AndroidJavaClass androidclass = null;
// Use this for initialization
void Start()
{
AndroidJavaClass activityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject activityContext = activityClass.GetStatic<AndroidJavaObject>("currentActivity");
androidclass = new AndroidJavaClass("com.mycompany.myproject.androidbridgeclass");
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
androidclass.CallStatic("displayDialogWithImages");
}
if (Input.GetKeyDown(KeyCode.Escape))
{
Application.Quit();
}
}
}
code of which side? Dialog appears perfect on android applications. But in Unity3d it doesn't work. I am Uploading Bridge Class Code.
Answer by MooOooN · Apr 24, 2015 at 12:54 PM
Ok So that is how I did it.
if (Input.GetMouseButtonDown(0))
{
currentActivity.Call("runOnUiThread", new AndroidJavaRunnable(() =>
{
androidclass.CallStatic("displayDialogWithImages");
}));
}
RunOnUiThread did the job.
Answer by bhavani0824 · Oct 13, 2016 at 10:55 AM
How to call non static method from android to unity 3d???
Your answer
