Also in the internet turned a lot of information, here refer to the Netizen's http://www.cnblogs.com/xiaozefeng/p/Unity_Android_IOS.html
But he didn't write it all, which led to the Android program eclipse will end up with an error
He wrote here
Unity3d Call Android Clipboard
Public classClipboardtools { Public StaticClipboardmanager Clipboard =NULL; //add text to the Clipboard Public voidCopytexttoclipboard (Final context context, Final String str) {if(Lopper.mylooper () = =NULL) {looper.prepare (); } Clipboard=(Clipboardmanager) Activity.getsystemservice (Activity.clipboard_service); Clipdata Textcd= Clipdata.newplaintext ("Data", str); Clipboard.setprimaryclip (TEXTCD); Handler.getlooper (). Quit (); } //get text from the Clipboard PublicString Gettextfromclipboard () {if(Clipboard! =NULL&& Clipboard.hasprimaryclip () &&clipboard.getprimaryclipdescription (). Hasmimetype (Clipdescription.mimetype_text_plain)) {Clipdata Cdtext=Clipboard.getprimaryclip (); Clipdata.item Item= Cdtext.getitemat (0); returnItem.gettext (). toString (); } return NULL; }}
However, running the program, the inevitable error
The workaround is to use the function to add text to the Clipboard as an example, because when a new thread is started, the code is as follows
Public voidCopytexttoclipboard (Final Context activity, Final String str) {NewThread (NewRunnable () {@Override Public voidrun () {looper.prepare (); M_handler=NewHandler () { Public voidhandlemessage (Message msg) {Clipboard=(Clipboardmanager) Activity.getsystemservice (Activity.clipboard_service); Clipdata Textcd= Clipdata.newplaintext ("Data", str); Clipboard.setprimaryclip (TEXTCD); } }; Message Message=NewMessage (); M_handler.sendmessage (message); Looper.loop (); }}). Start (); }
That's right.
Next:
Android Clipboard Item Import Unity3d
1. Create the plugins directory under the assets directory of the Untiy3d project.
2. Create an Android directory under the plugins directory.
3. Create the Bin directory in the Android directory.
4. In the bin directory, place the jar package for the class you are writing.
And then
Unity3d calling Android Classes and methods
#ifUnity_androidAndroidjavaobject Androidobject=NewAndroidjavaobject ("Com.test.ClipboardTools"); Androidjavaobject Activity=NewAndroidjavaclass ("Com.unity3d.player.UnityPlayer"). Getstatic<androidjavaobject> ("currentactivity");if(Activity = =NULL) return ; //Copy to ClipboardAndroidobject.call ("Copytexttoclipboard", activity, input); //get text from the ClipboardString Text =androidobject.call<string> ("Gettextfromclipboard");#endif
Ok,ios hasn't studied yet.
Unity3d The Android platform Clipboard implementation