Created
June 6, 2017 06:11
-
-
Save randhirraj3130/b73a50d99c61043ac410e8ee83da4f3b to your computer and use it in GitHub Desktop.
how to show the toast the in unity for android devices
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
public static void showToast(string text) | |
{ | |
if (Application.platform == RuntimePlatform.Android) { | |
AndroidJavaClass unityPlayer = new AndroidJavaClass ("com.unity3d.player.UnityPlayer"); | |
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject> ("currentActivity"); | |
AndroidJavaClass Toast = new AndroidJavaClass ("android.widget.Toast"); | |
AndroidJavaObject javaString = new AndroidJavaObject ("java.lang.String", text); | |
AndroidJavaObject context = currentActivity.Call<AndroidJavaObject> ("getApplicationContext"); | |
AndroidJavaObject toast = Toast.CallStatic<AndroidJavaObject> ("makeText", context, javaString, Toast.GetStatic<int> ("LENGTH_SHORT")); | |
toast.Call ("show"); | |
} else { | |
Debug.Log(text); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment