using UnityEngine; public class ClipBoard { public static void ExportString(string exportData) { #if UNITY_ANDROID AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject activity = jc.GetStatic<AndroidJavaObject>("currentActivity"); activity.Call("runOnUiThread", new AndroidJavaRunnable(() => { AndroidJavaObject clipboardManager = activity.Call<AndroidJavaObject>("getSystemService", "clipboard"); AndroidJavaClass clipDataClass = new AndroidJavaClass("android.content.ClipData"); AndroidJavaObject clipData = clipDataClass.CallStatic<AndroidJavaObject>("newPlainText", "clip text", exportData); clipboardManager.Call("setPrimaryClip", clipData); })); #endif } }
環境によってはcom.unity3d.player.UnityPlayer をcom.unity3d.player.UnityNativePlayerなどと変更する必要があるかと思われます。