close
當我們要複製文字時,unity的內建類別 TextEditor在 android裡是沒做用的,所以我們必需寫個jar包讓unity去調用 android的剪貼簿。
以下為 android上的代碼
// 將文字貼到剪貼板 public void CopyString(final Activity activity, final String str) { Log.i("CopyStringTools", "CopyString"); activity.runOnUiThread(new Runnable() { @Override public void run() { clipboard = (ClipboardManager) activity.getSystemService(Activity.CLIPBOARD_SERVICE); ClipData textCd = ClipData.newPlainText("data", str); clipboard.setPrimaryClip(textCd); } }); } // 從剪貼板取得文字 public void GetString(final Activity activity, final String gameObjectName, final String callName) { if(clipboard != null) { activity.runOnUiThread(new Runnable() { @Override public void run() { if (clipboard.hasPrimaryClip() && clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) { ClipData cdText = clipboard.getPrimaryClip(); ClipData.Item item = cdText.getItemAt(0); UnityPlayer.UnitySendMessage(gameObjectName, callName, item.getText().toString()); } } }); } }
全站熱搜
留言列表