Toast On Image Detection In Vuforia Either Using Unity Or Java Without C++
I have to Toast a message when an Image is detected. Which is the easiest way to do? Using Unity or just using JAVA without native calls? I've tried all the ways given in the devel
Solution 1:
I really appreciate your efforts. But there is a very simple way to do this:
Try this script
using UnityEngine; using System.Collections;
public class ShowToast : MonoBehaviour { // Use this for initialization void Start () { MyShowToastMethod (); } string toastString; AndroidJavaObject currentActivity; public void MyShowToastMethod () { if (Application.platform == RuntimePlatform.Android) { showToastOnUiThread ("It Worked!"); } } void showToastOnUiThread(string toastString){ AndroidJavaClass UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); currentActivity = UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); this.toastString = toastString; currentActivity.Call ("runOnUiThread", new AndroidJavaRunnable (showToast)); } void showToast(){ Debug.Log ("Running on UI thread"); AndroidJavaObject context = currentActivity.Call<AndroidJavaObject>("getApplicationContext"); AndroidJavaClass Toast = new AndroidJavaClass("android.widget.Toast"); AndroidJavaObject javaString=new AndroidJavaObject("java.lang.String",toastString); AndroidJavaObject toast = Toast.CallStatic<AndroidJavaObject> ("makeText", context, javaString, Toast.GetStatic<int>("LENGTH_SHORT")); toast.Call ("show"); } }
Solution 2:
I am using unity extension but i m pretty sure core codabase is the same. Image target uses the class called DefaultTrackableEventHandler and there is OnTrackingFound() function. This is called once the image is detected so you can implement your message in there! This is how I do it anyways. Good luck
Post a Comment for "Toast On Image Detection In Vuforia Either Using Unity Or Java Without C++"